Find and Replace text in the entire table using a MySQL query

The easiest way I have found is to dump the database to a text file, run a sed command to do the replace, and reload the database back into MySQL.

All commands below are bash on Linux.

Dump database to text file

mysqldump -u user -p databasename > ./dbname.sql

Run sed command to find/replace target string

sed -i 's/oldString/newString/g' ./dbname.sql

Reload the database into MySQL

mysql -u user -p databasename < ./dbname.sql

Leave a Comment

Your email address will not be published.