Free trial *Internet Service Required

Install MySQL on a virtual machine running Windows Server 2008 R2 in Windows Azure

MySQL is a popular open source, SQL database. Using the Windows Azure Management Portal, you can create a virtual machine running Windows Server 2008 R2 from the Image Gallery. You can then install and configure a MySQL database on the virtual machine.

In this tutorial, you will learn how to:

  • Use the Management Portal to create a virtual machine running Windows Server 2008 R2.

  • Install and run MySQL Community Server on the virtual machine.

Create a virtual machine running Windows Server 2008 R2

Note: This article creates a virtual machine that is not connected to a virtual network. If you want your virtual machine to use a virtual network so you can connect to your virtual machines directly by hostname or set up cross-premises connections, use the From Gallery method instead and specify the virtual network when you create the virtual machine. For more information about virtual networks, see Windows Azure Virtual Network Overview.

Follow these steps to create a virtual machine:

  1. Login to the Windows Azure Management Portal using your Windows Azure account.

  2. In the Management Portal, at the bottom left of the web page, click +New, click Virtual Machine, and then click From Gallery. Create a New Virtual Machine

  3. Select a Windows Server 2008 R2 SP1 virtual machine image, and then click the next arrow at the bottom right of the page.

  4. On the Virtual machine configuration page, provide the following information:

    • Provide a Virtual Machine Name, such as "testwinvm".
    • In the New User Name box, type "Administrator".
    • In the New Password box, type a strong password.
    • In the Confirm Password box, retype the password.
    • Select the appropriate Size from the drop down list.

    Click the next arrow to continue.

  5. On the Virtual machine mode page, provide the following information:

    • Select Standalone Virtual Machine.
    • In the DNS Name box, type a valid sub-domain in the format testwinvm.cloudapp.net
    • In the Region/Affinity Group/Virtual Network box, select a region where this virtual image will be hosted.

    Click the next arrow to continue.

  6. On the Virtual machine options page, select (none) in the Availability Set box. Click the check mark to continue.

  7. Wait while Windows Azure prepares your virtual machine.

Attach a data disk

Follow these steps to attach a data disk:

  1. In the Windows Azure Management Portal, click Virtual Machines and then select the virtual machine you just created (testwinvm).

  2. On the command bar click Attach and then click Attach Empty Disk.

    The Attach empty disk to virtual machine dialog box appears.

  3. The Virtual Machine Name, Storage Location, and File Name are already defined for you. All you have to do is enter the size that you want for the disk. Type 5 in the Size field.

    Attach Empty Disk

    Note: All disks are created from a VHD file in Windows Azure storage. You can provide a name for the VHD file that you add to storage, but Windows Azure generates the name of the disk automatically.

  4. Click the check mark to attach the data disk to the virtual machine.

  5. Click the name of the virtual machine to display the dashboard; this lets you verify that the data disk was successfully attached to the virtual machine.

    The number of disks is now 2 for the virtual machine. The disk that you attached is listed in the Disks table.

    Attach Empty Disk

    After you attach the data disk to the virtual machine, the disk is offline and not initialized. You have to log on to the virtual machine and initialize the disk before you can use it to store data.

Connect to the Virtual Machine Using Remote Desktop and Complete Setup

  1. After the virtual machine is provisioned, on the Management Portal, click Virtual Machines, and then click your new virtual machine. Information about your virtual machine is presented.

  2. At the bottom of the page, click Connect. Open the .rpd file using the Windows Remote Desktop program (%windir%\system32\mstsc.exe).

  3. At the Windows Security dialog box, provide the password for the Administrator account. (You might be asked to verify the credentials of the virtual machine.) The first time you log on to this virtual machine, several processes may need to complete, including setup of your desktop, Windows updates, and completion of the Windows initial configuration tasks. Once you are connected to the virtual machine with Windows Remote Desktop, the virtual machine works like any other computer.

  4. After you log on to the virtual machine, open Server Manager. In the left pane, expand Storage, and then click Disk Management.

    Server Manager

  5. The Initalize Disk window appears. Click OK.

    Initialize Disk

  6. Right-click the space allocation area for Disk 2, click New Simple Volume, and then finish the wizard with the default values.

    New Simple Volume

    The disk is now online and ready to use with a new drive letter.

    Initialize Success

Install and run MySQL Community Server on the virtual machine

Follow these steps to install, configure, and run MySQL Community Server:

  1. After you've connected to the virtual machine using Remote Desktop, open Internet Explorer from the Start menu.

  2. Select the Tools button in the upper right corner. In Internet Options, select the Security tab, and then select the Trusted Sites icon, and finally click the Sites button. Add http://*.mysql.com to the list of trusted sites.

  3. Go to Download MySQL Community Server.

  4. Select Microsoft Windows in the Platform drop down menu and click Select.

  5. Find the most recent release of Windows (x86, 64-bit), MSI Installer and click Download.

  6. Select No thanks, just start my download! (or, register for an account). If prompted, select a mirror site to download the MySQL installer and save the installer to the desktop.

  7. Double-click the installer file on the desktop to begin installation.

  8. Click Next.

    MySQL Setup

  9. Accept the license agreement and click Next.

    MySQL Setup

  10. Click Typical to install common features.

    MySQL Setup

  11. Click Install.

    MySQL Setup

  12. Start the MySQL Configuration Wizard and click Next.

    Configure MySQL

  13. Select Detailed Configuration and click Next.

    Configure MySQL

  14. Select Server Machine if you plan to run MySQL along with other applications on the server, or the select option that best fits your needs. Click Next.

    Configure MySQL

  15. Select Multifunctional Database, or the select option that best fits your needs. Click Next.

    Configure MySQL

  16. Select the data drive you attached in the steps above.

    Configure MySQL

  17. Select Decision Support (DSS)/OLAP, or the select option that best fits your needs. Click Next.

    Configure MySQL

  18. Select Enable TCP/IP Networking and Add firewall exception for this port (this will create an inbound rule in Windows Firewall named MySQL Server).

    Configure MySQL

  19. Select Best Support For Multilingualism if you need to store text in many different languages, or the select option that best fits your needs. Click Next.

    Configure MySQL

  20. Select Install As Windows Service and Launch the MySQL Server automatically. Also select Include Bin Directory in Windows PATH. Click Next.

    Configure MySQL

  21. Enter the root password. Do not check Enable root access from remote machines or Create An Anonymous Account. Click Next.

    Configure MySQL

  22. Click Execute and wait for configuration to complete.

    Configure MySQL

  23. Click Finish.

    Configure MySQL

  24. Click Start and select MySQL 5.x Command Line Client to start the command line client.

  25. Enter the root password at the prompt (which you set in a previous step) and you'll be presented with a prompt where you can issue SQL statements to interact with the database.

  26. To create a new MySQL user, run the following at the mysql> prompt:

    mysql> CREATE USER 'mysqluser'@'localhost' IDENTIFIED BY 'password';

    Note, the semi-colons (;) at the end of the lines are crucial for ending the commands.

  27. To create a database and grant the mysqluser user permissions on it, issue the following commands:

    mysql> CREATE DATABASE testdatabase;
    mysql> GRANT ALL ON testdatabase.* TO 'mysqluser'@'localhost' IDENTIFIED BY 'password';

    Note that database user names and passwords are only used by scripts connecting to the database. Database user account names do not necessarily represent actual user accounts on the computer.

  28. To login from another computer, execute the following:

    mysql> GRANT ALL ON testdatabase.* TO 'mysqluser'@'<ip-address>' IDENTIFIED BY 'password';

    where ip-address is the IP address of the computer from which you will connect to MySQL.

  29. To exit the MySQL command line client, issue the following command:

    quit
  30. Once MySQL is installed you must configure an endpoint so that MySQL can be accessed remotely. Log in to the Windows Azure Management Portal. In the Windows Azure portal, click Virtual Machines, then the name of your new virtual machine, then Endpoints, and then Add Endpoint.

    Endpoints

  31. Select Add Endpoint and click arrow to continue.

    Endpoints

  32. Add an endpoint with name "MySQL", protocol TCP, and both Public and Private ports set to "3306". Click the check mark. This will allow MySQL to be accessed remotely.

    Endpoints

  33. You can remotely connect to MySQL running on your virtual machine in Windows Azure. From a local computer running MySQL, run the following command to log in as the mysqluser user you created in the steps above:

    mysql -u mysqluser -p -h <yourservicename>.cloudapp.net

    For example, using the virtual machine created in this tutorial, the command would be:

    mysql -u mysqluser -p -h testwinvm.cloudapp.net

Summary

In this tutorial you learned how to create a Windows 2008 R2 virtual machine and remotely connect to it. You also learned how to install and configure MySQL on the virtual machine, create a database and a new MySQL user. For more information on MySQL, see the MySQL Documentation.

Rss Newsletter