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

Allow root access via SSH on CentOS

If you see the message: “Please login as the user “centos” rather than the user “root”  we need to allow root access via SSH.

  • Login as the user “centos”:
    # ssh -i PrivateKey.pem centos@Floating-IP-Address
  • Change to root:
    # sudo -s
  • Edit the file “/root/.ssh/authorized_keys”
    # vi /root/.ssh/authorized_keys
    and keep it only contains the key  (starts with “sh-rsa”) without the restrictions that exist at the begining of the file.
  • Open the sshd_config # vi/etc/ssh/sshd_config
    and uncomment the line “PermitRootLogin yes”
  • Restart SSH daemon:
    # systemctl restart sshd

Now you can SSH as root to your instance, high five!

© 2021 - FreshLondon