Link MySQL Database To Azure Virtual Machine And WordPress

In this article we will explain you how you can link your existing MySQL database to Azure virtual machine and configure in WordPress.

This article explains how you can link your existing MySQL database to Azure virtual machine and configure in wordpress. Once your database and wordpress website id ready, you can go ahead and link your DB to wordpress and azure virtual machine. If you need to back up and restore your clear db MySQL database in a virtual machine in Azure, I hope you will like this.

If you are new to azure, I recommend you to read here: Azure

Background

I hope you read my articles related to Virtual Machines in azure. If not, please read those. I was being limited to use only 20 MB size since one of the MSDN subscription was providing me ClearDB. So I thought of creating a virtual machine and install MySQL. Then I restored my previous database to my new Database. Here in this article, I will share you the steps to link the database you created to azure virtual machine and wordpress.

  • Please read this article in my blog here .
  • Steps to Back Up your ClearDB and restore.
  • Login to your azure portal.
  • Login to your Azure Virtual Machine.
  • Hope you have already installed MySQL in your Virtual Machine. If so, we are ready to go.
  • First thing we need to do is to add the end points in our Azure virtual machine. To do so you need to follow the below steps.
  • Add end points in Azure virtual machine.
  • Go to your virtual machine in azure management portal.
Adding end points in Azure Virtual Machine

Adding end points in Azure Virtual Machine

Now click on the ENDPOINTS as in the following screenshot:

Adding end points in Azure Virtual Machine

Adding end points in Azure Virtual Machine.

Click on the ADD option in the footer area.

Adding end points in Azure Virtual Machine

Adding end points in Azure Virtual Machine

Now you will be getting a pop up, in that please click on the Add standalone end points.

Adding end points in Azure Virtual Machine

Adding end points in Azure Virtual Machine.

In the given area, please select MySQL as name and TCP as protocol. Port should be the one we did it while configuring the MySQL. For example, 3306. I suggest you to do not edit in that area.

Adding end points in Azure Virtual Machine

Adding end points in Azure Virtual Machine.

Click on the tick icon once you have made entry for the required fields. Then you can see the progression and once it is completed, you will get a message as in the following screenshot:

Adding end points in Azure Virtual Machine

Adding end points in Azure Virtual Machine.

So we have successfully created the end points for our virtual machine MySQL. The next step is, to change some settings in the firewall in our virtual machine. Please do this with some care. It is very much important.

Setting the firewall configuration in Azure virtual machine

Go to the start menu and type power shell. You will be given some search results.

Setting the firewall configuration in Azure virtual machine

Setting the firewall configuration in Azure virtual machine.

Now you can see a command window with the name of logged in user as i the following screenshot:

Setting the firewall configuration in Azure virtual machine

Setting the firewall configuration in Azure virtual machine.

The next step is a bit complex one. You need to enter a complex command which is shown here.

Setting the firewall configuration in Azure virtual machine

Setting the firewall configuration in Azure virtual machine.

For your convenience I am giving the following command:

  1. New-NetFirewallRule -DisplayName "MySQL56" -Direction Indound -Protocol TCP -LocalPort 3306 -Action Allow -Profile Public  
You can type the following command:

 

Setting firewall in azure virtual machine

Setting firewall in azure virtual machine.

And if you do the above step correctly, I am sure you will be given a result as follows.

Setting firewall in azure virtual machine

Setting firewall in azure virtual machine.

Wow, we have done the settings needed now.

Now we need to change some settings in our wordpress configuration. As you all know the wordpress configuration is in the file called wp-config.php. So we are going to change the configuration in that file.

Changing the configuration to new settings in wordpress.

Again go to your manage azure page, click the web application you need to change the settings.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress

Now go to the dashboard and click Edit in Visual Studio Online.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress.

You can see your wordpress files now. Click on the wp-config.php.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress.

It is always better to take a back up or copy of the wp-config.php, so that you can revert back to your clearDB configuration whenever you want. I strongly recommend you to do this step.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress.

You can rename the pasted file, just right click on the file and click Rename.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress

As you can see in the following image, I have given the name ClearDB-Wp-Config.php.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress.

Open your wp-config.php and change the MySQL host name.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress.

Now add the port number in the host name because it listen that port.

Changing the configuration to new settings in wordpress

Changing the configuration to new settings in wordpress.

Please do not forget to change the database name, user name, password too.

Now I am sure your blog with new MySQL database will be running . Keep blogging. Cheers!.

Conclusion

Did I miss anything that you may think which is needed?.Have you ever tried virtual machine in azure?. If not, I strongly recommend that. So we have successfully configured our new MySQL database to the Azure virtual machine and wordpress. We have also done the firewall changes needed in virtual machine. I hope you liked this article. Please share me your valuable suggestions and feedback.

Your turn. What do you think

A blog isn’t a blog without comments, but do try to stay on topic. Write your questions and feedback in the comments section below.