Restoring MySQL Database for WordPress

Backing up is one thing and restoring the data is another important piece to migrate a WordPress site. Restoring the data and being able to access from the Dockerized WordPress was not easy for me.

I restored the entire database and I tried to access it from the newly Dockerized WordPress instance but it would not work. It raise page took too long to load type of error. What I resorted to do is to restore database as blog_bak and exported data from several tables and then imported them to the new database and the site worked. I will write about it in detail.

Open your backed up database file (.sql) in a texteditor and change the following part where it tries to create the database with the original database name to blog_bak so that the database name does not conflict with the new one instance. If you don’t see CREATE DATABASE statement at the beginning of the file, you may have to re-export your database with custom export with Add CREATE DATABASE option.

-- Database: `hayato_iriumi_db`
USE `blog_bak`;

Zip the database backup to [youfilename] to get ready to be restored on the target MySQL Server. It is much faster to restore database using a zipped file.

Navigate to Import tab on the target MySQL Server and upload the zip file to restore your old database to blog_bak database.

This will restore your blog database to blog_bak. I am going to stop here because we haven’t gone over spinning up the new MySQL Server with Docker yet. You can get ready up to the point where editing the exported SQL file.

Will continue on this topic later because there is a lot more to cover.

Leave a Reply

Your email address will not be published.