User Tools

Site Tools


computing:migratewp

This is an old revision of the document!



  • migratewp
  • Jonathan Haack
  • Haack's Networking
  • netcmnd@jonathanhaack.com

migratewp


This tutorial is designed to step one through how to migrate a mysql database to another host. The tutorial is named migratewp, because I first did this on a WP instance. First, use mysqldump to dump the entire database:

sudo -i
/usr/bin/mysqldump    \
--add-drop-database \
--all-databases     \
--allow-keywords    \
--comments          \
--complete-insert   \
--lock-all-tables   \
--skip-dump-date    \
--events            \
--flush-logs        \
--flush-privileges  \
--hex-blob          \
--opt               \
--routines          \
> mysqldump-all-databases.sql

Use scp to get the file to the new host:

sudo scp mysqldump-all-databases.sql user@newhostorip.com:

Before your import the mysqldump databases into the new database, you need to create what I call a “surrogate” user and database to do the heavy lifting for you first. You will also grant this surrogate user super privileges.

CREATE DATABASE temp;
CREATE USER tempuser@localhost IDENTIFIED BY 'tempass';
GRANT ALL PRIVILEGES ON temp.* to tempuser@localhost IDENTIFIED BY 'tempass';
FLUSH PRIVILEGES;
EXIT;

Now that you have created a temporary database and database user with full privileges, it is time to import the backup. The second command is what I used on some temperamental instance. The first command below is simple enough and should work. I retain both just in case an instance talks back to me.

mysql -u tempuser -p temp < /path/to/backup-databases.sql
mysql -u tempuser -h localhost -p --database=temp < /path/to/backup-databases.sql

Once it finishes, log into the mysql command mode and verify the original databases made it over:

sudo mysql -u user -p
> SHOW DATABASES;
> EXIT

After the database is migrated, simply copy all the files from web root for the instance over to the new host. Ensure that permissions and configuration files are appropriate, then reboot. Once the database is migrated, you can delete the surrogate user and database as follows:

  DROP DATABASE temp;
  DROP USER 'tempuser'@'localhost';

That should be all there is to it!

oemb1905 2022/07/31 11:42

computing/migratewp.1659289837.txt.gz · Last modified: 2022/07/31 17:50 by oemb1905