Migrate your local mysql db to Azure mysql

  • fennng 

Last time, I introduced deploying a new wordpress on azure. But in the real case, you may already have a wordpress running on your local machine with a lot of fancy plugins and some cool pages.

Instead of let wordpress to init an empty database, you may would like to migrate your local mysql database to azure.

I will show you how this can be done.

The first thing is dumping your database to a file. This can be done by using mysqldump command or any other mysql tools such as phpmyadmin.

If you are running mysql in a docker container like what I am doing, use the following command:

docker exec container-name /usr/bin/mysqldump -u root –password=yourpassword wordpress > backup.sql

Or alternatively, you can use phpmyadmin to connect to mysql and export from phpmyadmin

docker run –name tempmyadmin –rm -d –network=wp-net –link wp-mysql:db -p 8060:80 phpmyadmin/phpmyadmin

Then you will need to import your dumped file to azure mysql server. I use phpmyadmin to do this.

docker run –name myadmin -d -e PMA_HOST=azure-dbhost -p 8080:80 phpmyadmin/phpmyadmin

Before importing, you may need to drop the old db and recreate an empty one with phpmyadmin. Once imported, you will need to update the URLs in options table to match the new azure wordpress domain.

Now, back to your wordpress website, you will notice that all the posts and pages appear.

If you have customized your wordpress locally, you may notice that your plugins and customized themes are gone. Because these settings are not in database. You will need to migrate your whole wordpress in your localhost to Azure, I will cover this bit later.


您的电子邮箱地址不会被公开。 必填项已用*标注