Skip to content

Instantly share code, notes, and snippets.

@altescape
Created October 10, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altescape/29c818523b16a651ca3b75a7c266fbbf to your computer and use it in GitHub Desktop.
Save altescape/29c818523b16a651ca3b75a7c266fbbf to your computer and use it in GitHub Desktop.
Find and replace something in a database table using SED

Take a backup

mysqldump -u USERNAME -p --databases DATABASENAME > dump-all.sql

Dump the table

mysqldump -u USERNAME -p DATABASENAME TABLENAME > dump.sql

Use sed to find and replace text

sed "s:OLD_TEXT:NEW_TEXT:g" dump.sql > dump_with_replaced_text.sql

Import data back into database

mysql -u USERNAME -p DATABASENAME < dump_with_replaced_text.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment