PDA

View Full Version : How to search and replace in MySQL database as a Linux root user



Fli
08-05-2016, 11:56 AM
How to replace sme phrasse in MySQL database having root access to the Linux server?

Downside of this method is that if someone write into database during replacement, his changes will be lost.

Export database into a file and duplicate the file for backup purpose:

mysqldump -u root -p databasename > db_orig.sql;cp -p db_orig.sql db_modiffied.sql

Make replacement (cAsE sensitive!!):

sed -i 's/OldString/NewString/g' db_modiffied.sql

Import modiffied mysql file:

mysql -u user -p databasename < db_modiffied.sql

-----
But how to do case insensitive replacement? Someone adviced: perl -pe 's/old/new/i'