Install MySQL on a virtual machine running Windows Server 2012 R2 in Azure
MySQL is a popular open source, SQL database. Using the Azure Management Portal, you can create a virtual machine running Windows Server 2012 R2 from the Image Gallery. You can then install and configure it as a MySQL Server.
This tutorial shows you how to:
Create a virtual machine running Windows Server
Sign in to the Azure Management Portal. Check out the Free Trial offer if you don't have a subscription yet.
On the command bar at the bottom of the window, click New.
Under Compute, click Virtual Machine, and then click From Gallery.
The first screen lets you Choose an Image for your virtual machine from one of the lists in the Image Gallery. (The available images may differ depending on the subscription you're using.) Click the arrow to continue.
The second screen lets you pick a computer name, size, and administrative user name and password. If you just want to try out Azure Virtual Machines, fill in the fields as shown in the image below. Otherwise, chose the tier and size required to run your app or workload. Here are some details to help you fill this out:
- New User Name refers to the administrative account that you use to manage the server. Create a unique password for this account and make sure to remember it. You'll need the user name and password to log on to the virtual machine.
- A virtual machine's size affects the cost of using it, as well as configuration options such as the number of data disks you can attach. For details, see Virtual Machine and Cloud Service Sizes for Azure.
The third screen lets you configure resources for networking, storage, and availability. Here are some details to help you fill this out:
- The Cloud Service DNS Name is the global DNS name that becomes part of the URI that's used to contact the virtual machine. You'll need to come up with your own cloud service name because it must be unique in Azure. Cloud services are important for scenarios using multiple virtual machines.
- For Region/Affinity Group/Virtual Network, use a region that's appropriate to your location. You can also choose to specify a virtual network instead.
The fourth configuration screen lets you configure the VM Agent and some of the available extensions. Click the check mark to create the virtual machine.
The VM agent provides the environment for you to install extensions that can help you interact with or manage the virtual machine. For details, see Using Extensions.
After the virtual machine is created, the Management Portal lists the new virtual machine under Virtual Machines. The corresponding cloud service and storage account also are created and are listed in those sections. Both the virtual machine and cloud service are started automatically and the Management Portal shows their status as Running.
Attach a data disk
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 is currently limited to 127 GB and 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.
Log on to the virtual machine
Next, you'll log on to the virtual machine so you can install MySQL.
If you haven't already done so, sign in to the Azure Management Portal.
Click Virtual Machines, and then select the appropriate virtual machine.
On the command bar, click Connect.
Click Open to use the Remote Desktop Protocol file that's automatically created for the virtual machine.
Click Connect to continue.
Type the credentials for the administrative account on the virtual machine, and then click OK.
In most cases, you'll use the user name and password that was specified when the virtual machine was created. Check the user name to make sure it has the correct domain information:
- If the VM belongs to a domain at your organization, make sure the user name includes the name of that domain.
- If the VM doesn't belong to a domain, either remove any domain information by starting the line with '\' or use the VM name as the domain name. For example,
- If the VM is a domain controller, type the user name and password of a domain administrator account for that domain.
Click Yes to verify the identity of the virtual machine.
You can now work with the virtual machine remotely.
Install and run MySQL Community Server on the virtual machine
Follow these steps to install, configure, and run the Community version of MySQL Server:
These steps are for the 126.96.36.199 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-188.8.131.52.msi with a file size of 282.4 MB), and save the installer file to the Windows desktop.
- From the desktop, double-click the installer file to begin installation.
- 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. Click 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 Management 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 this command at an administrator-level Windows PowerShell command prompt on the MySQL server computer.
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 Management 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 this 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, this is the command:
mysql -u dbadmin3 -p -h testmysql.cloudapp.net
For information on MySQL, see the MySQL Documentation.