Andy Andy - 4 months ago 7
SQL Question

Find and replace in entire mysql database

i would like to do a find and replace inside an entire database not just a table.

How can i alter the script below to work?


update [table_name] set [field_name] =
replace([field_name],'[string_to_find]','[string_to_replace]');


Do i just use an asterix?


update * set [field_name] =
replace([field_name],'[string_to_find]','[string_to_replace]');

Answer

sqldump to a text file, find/replace, re-import the sqldump.

Dump the database to a text file
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

Restore the database after you have made changes to it.
mysql -u root -p[root_password] [database_name] < dumpfilename.sql