Azure-Migrating WordPress Blog to Independent MySql from MySql In App

Migrating WordPress Blog to Independent mysql from mysql In App in Azure should have been easier but it was not! Azure let’s you create WordPress app service on the fly and it lets you use mysql In App without having a dedicated mysql database. In App version of mysql is easy to get started but it is not designed for production application. You would have to migrate to out-of-proc mysql database which you can do by adding Azure Database for mysql Server (add-on service). So, how do you migrate wordpress site from In App from mysql (and don’t want to go through the trouble)?

There are many articles on how to migrate and they are helpful. Those documentations were good yesterday but they may not work today as Azure Services are being updated each day! I followed Migrate your MySQL database by using import and export to create Azure Database for mysql Server and used MySql Workbench to create an empty database. Well, you can’t connect to mysql server from MySql Workbench because of IP restriction at the Azure Database for mysql Server. I was able to connect from Workbench after I added my local IP at Azure Database for mysql (@Connection Security).

Problem started when I was trying to export data from WordPress app (@ MySql In App) to newly created mysql. There are two options- Credentials and ConnectionString. ConnectionString provided at the Azure Database for mysql Server did not work. After few tries I moved to use Credentials but I could not connect to mysql instance! Why? It was because the IP address of WordPress app server was not added to allowed list! I got the IP address from Custom Domains section and added to Azure Database for mysql (@Connection Security). WordPress server is dynamic and you would not know all the IP’s. So, best way to handle this is to turn ON Allow Access to Azure Service on mysql.

Okay, I am able to make the connection and export started but I still can’t export the data from MySql In App! One of the reason is- WordPress app is using In App mysql and it was not running until I visited the blog site. Should not Microsoft document this and warn users? I guess they said it somewhere! I made sure mysqlid process is running (@Process Explorer) before retrying the export. Sadly, it failed!

Well, now that the In App mysql is running, I was able to use Manage (at the top of MySql In App) and it opened the PHPMyAdmin. That encouraging. This was where I exported all the tables from localdb to a file (sql fotmat). I was able to use MySQL Workbench and import the exported file. Remember, I already created a new database (schema is synonymous to DB). All I did is- opened the Sql file in Query explorer and added use mydatabase; at the beginning of the long script. Import was successful and it is because Azure understands the format at the both end of export/import. My attempt to bring the same blog data from my previous hosting company did not work because of formats. Getting there finally, I guess!

Now that I have the working mysql database, it’s time to setup connection string at the Application Settings of WordPress app. This is another painful experience as documentation does not meet the reality! Remember, the connectionstring did not work during export from In App. It did not work at the Application Settings either. No surprise! I get connection error after I added the connection string. Next, I moved to see how things are defined in wp-config.php file via App Service Editor (I liked this editor, a life savor). Code is looking for a connection string with name starting with “MYSQLCONNSTR_”. I did not know this but you will not miss it when you look at the connection info in MySql In App. Also, code is parsing connection attributes does not match with what described at the Azure Database for mysql. Code is looking for connection string like- Data Source=yourdb.mysql.database.azure.com;Database=your-mysql-db-name;User Id=your-user-id-@Azure Database for mysql;Password=userspassword.

While I am there at the wp-config, I updated the secrete key section. You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.

One more thing, you want to turn the debug flag during this setup stage. Be sure to turn it to false once done. This was helpful because I could see the real error messages afterward. You don’t want keep debug flag for security reason.

Back to Application Settings of WordPress app, I created a new MySql connection with a key name MYSQLCONNSTR_prod and value like: Data Source=yourdb.mysql.database.azure.com;Database=your-mysql-db-name;User Id=your-user-id-@Azure Database for mysql;Password=userspassword. Change the settings based your own mysql credentials.

Go to MySql In App and turn off the local In App mysql. You would be able to figure out if there is any error since we have the debug mode on in wp-config. It worked for me. I immediately turned off the debug mode as I don’t like hackers to see system errors.

Happy migration of WordPress Blog to Independent mysql from mysql In App in Azure. Hope this information was helpful to you.

Leave a Reply