Search and Replace in MySQL database with phpMyAdmin

Do a search and replace in any MySQL database in phpMyAdmin. You do not need to download the database export at all, just run this simple command. This also works through the MySQL command line.

To search and replace a text string, start up phpMyAdmin, and click on your database name that you want to run the search and replace through. At the top of the window, click on the "SQL" tab.

In the text box, enter the following code. This is the generic setup, so edit to satisfy your needs:

UPDATE tablename SET tablefield = replace(tablefield,"findstring","replacestring");

You can add a WHERE clause onto this as well.

For example, here is one command a ran:

UPDATE `mos2_content` SET introtext = replace(introtext,"<p>","") WHERE `title` REGEXP '-0';

This got rid of all paragraph tags in the mos2_content table where the title included the string "-0".

Hope this helps. If you have any comments, suggestions, questions, or your own code, please submit a comment below.


Warning: require(/home/zimmer/zimmertech.com/css/images/404.php): failed to open stream: No such file or directory in /home/zimmer/zimmertech.com/tutorials.php on line 56

Fatal error: require(): Failed opening required '/home/zimmer/zimmertech.com/css/images/404.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/zimmer/zimmertech.com/tutorials.php on line 56