MySQL has a built in function to perform string replace (just like PHP str_replace) thru the query. I just perform a MySQL string replace at a website migration and everything work like a charm. This MySQL string replace function really save me a lot of time! Imagine if i’m going to edit the record one by one, and there is 100 record, i think i’m going to be crazy after the manual edition.
To perform string replace (str_replace) in MySQL, you can use the query below:-
Advertisements
- For example: I’m going to do string replace at my ‘post_content’ field in ‘wp_posts’ table.
Find: http://www.abc.com
Replace with: http://www.xyx.comYou may run the query below to perform the string replace function:-
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.abc.com','http://www.xyz.com');
- Done. Now all the record in post_content should be updated!
Related posts:
MySQL: Full text search for multiple words
MySQL replication stop at Last Errno 1062
Common MySQL database maintenance command
phpmyadmin disable 1440 timeout with auto login
How to backup MySQL Database in command line with compression
How to install apache, php, mysql with macport in Mac OS X
MySQL 5.5 PDO::__construct(): The server requested authentication method unknown to the client [mysq...
How to restore MySQL database from sql dump file?
Share this with your friends:-