Fast find and replace for URLs on MySQL databases via CLI

  1. SSH to the server using your favourite CLI.
  2. switch to a superuser
    # sudo su # cd /var/lib/mysql
  3. dump from live database to an actual .sql file
    # mysqldump live_database > live_database.sql
  4. change the URL in the database
    # sed -i 's/livedomain.com/stagingdomain.com/g' ./live_database.sql
  5. Import the modified dump to the staging database
    # mysql staging_database < ./live_database.sql
  6. remove the dump file
    # rm live_database.sql
© 2021 - FreshLondon