Fast find and replace for URLs on MySQL databases via CLI
- SSH to the server using your favourite CLI.
- switch to a superuser
# sudo su
# cd /var/lib/mysql
- dump from live database to an actual .sql file
# mysqldump live_database > live_database.sql
- change the URL in the database
# sed -i 's/livedomain.com/stagingdomain.com/g' ./live_database.sql
- Import the modified dump to the staging database
# mysql staging_database < ./live_database.sql
- remove the dump file
# rm live_database.sql