In this article, we will review how to migrate from ClearDB to MySQL in the application for a Wordpress instance running as PaaS in Azure.

Scenario: 

  • A Wordpress blog hosted as PaaS using the services of the ClearDB + Azure application.

Objective: 

  • Migrate from ClearDB to MySQL in Azure without the need to redeploy the webapp instance.
When analyzing the offer of the Azure marketplace, we can find different ways to implement the Wordpress instance through PaaS / IaaS:

wordpress-wikiazure


  • MySql in App ... creating from scratch the web application + the database and then restoring the database
  • Provision the VM with mySQL and then associate it with the webapp instance
  • Enable MySql in App - directly on the pp that had already been provisioned in Azure.

Migrating from ClearDB to MySQL 


Configuring MySQL in App

The configuration of the new MySQL database is very simple, all you have to do is open your web application in the Azure portal and click on MySQL in App in the application option.

wordpress1-wikiazure



Change the MySQL option in the application to On and save this configuration. Once you have finished creating MySQL, click on the Manage option in the upper left corner:

mysqlinapp - wikiazure


If you click on admin, you will see that you are an administrator of the PHPMyAdmin site.

TIP: I recommend that you save the ClearDB connection string and make a previous backup

phpmyadmin - wikiazure



When you click on export in mySQL in the application, the process to move the database will start, this could take a while depending on the size of your database ...

MySQL in App - wikiazure



What´s next? 

Complete Migration from ClearDB to MySQL in App


Go to Manage, and import the ClearDB database, we will use the connection string that we previously saved, that connection string will help us simplify the following steps, once you make this export, you can go to the Settings of the application and delete the ClearDB connection string, but wait a second! Before doing so, you must make some changes to your wp-config file

By default, your wordpress connection to your database looks like this:


define (
'DB_NAME''databasename');<br>
define ('DB_USER''username');<br>
define ('DB_PASSWORD''password');<br>
define ('DB_HOST''mydatabase.cloudapp.net');<br>




We will make the following modification:


$ connectstr_dbhost = '';<br>
$ connectstr_dbname = '';<br>
$ connectstr_dbusername = '';<br>
$ connectstr_dbpassword = '';<br>
 <br>
foreach ($ _SERVER as key => $ value) {<br>
 if (strpos ($ key"MYSQLCONNSTR_")! == 0) {<br>
 continue;<br>
 }<br>
 <br>
 $ connectstr_dbhost = preg_replace ("https://wikiazure.azureedge.net/^.*Data Source = (. +?);. * $ /""\\ 1", $ value);<br>
 $ connectstr_dbname = preg_replace ("https://wikiazure.azureedge.net/^.*Database=(.+?);.*$/""\\ 1", $ value);<br>
 $ connectstr_dbusername = preg_replace ("https://wikiazure.azureedge.net/^.*UserID = (. +?);. * $ /""\\ 1", $ value);<br>
 $ connectstr_dbpassword = preg_replace ("https://wikiazure.azureedge.net/^.*Password=(.+?)$/""\\ 1", $ value);<br>
}<br>
 <br>
define ('DB_NAME', $ connectstr_dbname);<br>
define ('DB_USER', $ connectstr_dbusername);<br>
define ('DB_PASSWORD', $ connectstr_dbpassword);<br>
define ('DB_HOST', $ connectstr_dbhost);



TIPThe instance of MySql in the application only connects locally, so only the port will be what should change in your case. That's why you need to download the connection string, which is managed by AppService.

By defaults, User ID is set to  'azure' and password 'password'

BEST PRACTICE: 

Sometimes, Wordpress updates and site extensions may conflict with your current Wordpress environment. If you are running Wordpress as PaaS, you may want to disable updates by default. To disable these updates you must place in your wp-config.php file:


define ('AUTOMATIC_UPDATER_DISABLED'true); // para deshabilitar las actualizaciones


or


define ('WP_AUTO_UPDATE_CORE'false); //Deshabilitar a nivel core.


Other Languages: 



Spanish(es-mx):