Install MySQL on a virtual machine created with the classic deployment model running Windows Server 2012 R2
MySQL is a popular open source, SQL database. This tutorial shows you how to install and run the community version of MySQL 5.6.23 as a MySQL Server on a virtual machine running Windows Server 2012 R2. For instructions on installing MySQL on Linux, refer to: How to install MySQL on Azure.
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource Manager model.
If you don't already have a VM running Windows Server 2012 R2, you can use this tutorial to create the virtual machine.
After the virtual machine is created, you can optionally attach an additional data disk. This is recommended for production workloads and to avoid running out of space on the OS drive (C:), which includes the operating system.
See How to attach a data disk to a Windows virtual machine and follow the instructions for attaching an empty disk. Set the host cache setting to None or Read-only.
Next, you'll log on to the virtual machine so you can install MySQL.
Follow these steps to install, configure, and run the Community version of MySQL Server:
These steps are for the 22.214.171.124 Community version of MySQL and Windows Server 2012 R2. Your experience might be different for different versions of MySQL or Windows Server.
- After you've connected to the virtual machine using Remote Desktop, click Internet Explorer from the start screen.
- Select the Tools button in the upper-right corner (the cogged wheel icon), and then click Internet Options. Click the Security tab, click the Trusted Sites icon, and then click the Sites button. Add http://*.mysql.com to the list of trusted sites. Click Close, and then click OK.
- In the address bar of Internet Explorer, type http://dev.mysql.com/downloads/mysql/.
- Use the MySQL site to locate and download the latest version of the MySQL Installer for Windows. When choosing the MySQL Installer, download the version that has the complete file set (for example, the mysql-installer-community-126.96.36.199.msi with a file size of 282.4 MB), and save the installer.
- When the installer has finished downloading, click Run to launch setup.
- On the License Agreement page, accept the license agreement and click Next.
- On the Choosing a Setup Type page, click the setup type that you want, and then click Next. The following steps assume the selection of the Server only setup type.
- On the Installation page, click Execute. When installation is complete, click Next.
- On the Product Configuration page, click Next.
On the Type and Networking page, specify your desired configuration type and connectivity options, including the TCP port if needed. Select Show Advanced Options, and then click Next.
On the Accounts and Roles page, specify a strong MySQL root password. Add additional MySQL user accounts as needed, and then click Next.
On the Windows Service page, specify changes to the default settings for running the MySQL Server as a Windows service as needed, and then click Next.
On the Advanced Options page, specify changes to logging options as needed, and then click Next.
On the Apply Server Configuration page, click Execute. When the configuration steps are complete, click Finish.
On the Product Configuration page, click Next.
On the Installation Complete page, click Copy Log to Clipboard if you want to examine it later, and then click Finish.
From the start screen, type mysql, and then click MySQL 5.6 Command Line Client.
Enter the root password that you specified in step 11 and you'll be presented with a prompt where you can issue commands to configure MySQL. For the details of commands and syntax, see MySQL Reference Manuals.
You can also configure server configuration default settings, such as the base and data directories and drives, with entries in the C:\Program Files (x86)\MySQL\MySQL Server 5.6\my-default.ini file. For more information, see 5.1.2 Server Configuration Defaults.
If you want the MySQL Server service to be available to MySQL client computers on the Internet, you must configure an endpoint for the TCP port on which the MySQL Server service is listening and create an additional Windows Firewall rule. This is TCP port 3306 unless you specified a different port on the Type and Networking page (step 10 of the previous procedure).
You should carefully consider the security implications of doing this, because this will make the MySQL Server service available to all computers on the Internet. You can define the set of source IP addresses that are allowed to use the endpoint with an Access Control List (ACL). For more information, see How to Set Up Endpoints to a Virtual Machine.
To configure an endpoint for the MySQL Server service:
- In the Azure classic portal, click Virtual Machines, click the name of your MySQL virtual machine, and then click Endpoints.
- In the command bar, click Add.
- On the Add an endpoint to a virtual machine page, click the right arrow.
- If you are using the default MySQL TCP port of 3306, click MySQL in Name, and then click the check mark.
- If you are using a different TCP port, type a unique name in Name. Select TCP in protocol, type the port number in both Public Port and Private Port, and then click the check mark.
To add a Windows Firewall rule that allows MySQL traffic from the Internet, run the following command at an elevated Windows PowerShell command prompt on the MySQL server virtual machine.
New-NetFirewallRule -DisplayName "MySQL56" -Direction Inbound –Protocol TCP –LocalPort 3306 -Action Allow -Profile Public
To test your remote connection to the MySQL Server service running on the Azure virtual machine, you must first determine the DNS name corresponding to the cloud service that contains the virtual machine running MySQL Server.
- In the Azure classic portal, click Virtual Machines, click the name of your MySQL server virtual machine, and then click Dashboard.
From the virtual machine dashboard, note the DNS Name value under the Quick Glance section. Here is an example:
From a local computer running MySQL or the MySQL client, run the following command to log in as a MySQL user.
mysql -u <yourMysqlUsername> -p -h <yourDNSname>
For example, for the MySQL user name dbadmin3 and the testmysql.cloudapp.net DNS name for the virtual machine, use the following command.
mysql -u dbadmin3 -p -h testmysql.cloudapp.net
To learn more about running MySQL, see the MySQL Documentation.