Install MySQL on a virtual machine running OpenSUSE Linux in Windows Azure
MySQL is a popular open source, SQL database. Using the Windows Azure Management Portal, you can create a virtual machine running OpenSUSE Linux 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 an OpenSUSE Linux virtual machine from the gallery.
- How to connect to the virtual machine using SSH or PuTTY.
- How to install MySQL on the virtual machine.
Sign up for the Virtual Machines preview feature
You will need to sign up for the Windows Azure Virtual Machines preview feature in order to create a virtual machine. You can also sign up for a free trial account if you do not have a Windows Azure account.
To complete this tutorial, you need a Windows Azure account. You can create a free trial account in just a couple of minutes. For details, see Windows Azure Free Trial.
Create a virtual machine running OpenSUSE Linux
Important: If you want your virtual machine to use a virtual network, make sure you specify the virtual network when you create the virtual machine. A virtual machine can be configured to join a virtual network only when you create the virtual machine. For more information about virtual networks, see Windows Azure Virtual Network Overview.
Login to the Windows Azure Management Portal using your Windows Azure account.
In the Management Portal, at the bottom left of the web page, click +New, click Virtual Machine, and then click From Gallery.
Select an OpenSUSE virtual machine image from Platform Images, and then click the next arrow at the bottom right of the page.
On the Virtual machine configuration page, provide the following information:
- Provide a Virtual Machine Name, such as "testlinuxvm".
- Specify a New User Name, such as "newuser", which will be added to the Sudoers list file.
- 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.
On the Virtual machine mode page, provide the following information:
- Select Standalone Virtual Machine.
- In the DNS Name box, type a valid DNS address. For example, "testlinuxvm".
- In the Region/Affinity Group/Virtual Network box, select a region where this virtual image will be hosted.
Click the next arrow to continue.
On the Virtual machine options page, select (none) in the Availability Set box. Click the check mark to continue.
Wait while Windows Azure prepares your virtual machine.
Once the virtual machine is created you must configure endpoints in order to remotely connect.
In the Management Portal, click Virtual Machines, then click the name of your new virtual machine, then click Endpoints.
Click Edit Endpoint at the bottom of the page, and edit the SSH endpoint so that its Public Port is 22.
Connect to the Virtual Machine
When the virtual machine has been provisioned and the endpoints configured you can connect to it using SSH or PuTTY.
Connecting Using SSH
If you are using a linux computer, connect to the VM using SSH. At the command prompt, run:
$ ssh firstname.lastname@example.org -o ServerAliveInterval=180
Enter the user's password.
Connecting using PuTTY
If you are using a Windows computer, connect to the VM using PuTTY. PuTTY can be downloaded from the PuTTY Download Page.
Download and save putty.exe to a directory on your computer. Open a command prompt, navigate to that folder, and execute putty.exe.
Enter "testlinuxvm.cloudapp.net" for the Host Name and "22" for the Port.
Update the Virtual Machine (optional)
Once you've connected to the virtual machine, you can optionally install system updates and patches. Run:
$ sudo zypper update
Select Software then Online Update. A list of updates is displayed. Select Accept to start the installation and apply all new patches (except the optional ones) that are currently available for your system.
After installation is complete, select Finish. Your system is now up to date.
Install and run MySQL on the virtual machine
To escalate privileges, run:
Enter your password.
Run the following command to install MySQL Community Server edition:
# zypper install mysql-community-server
Wait while MySQL downloads and installs.
To set MySQL to start when the system boots, execute the following command:
# insserv mysql
Now you can manually start the MySQL daemon (mysqld) with the following command:
# rcmysql start
To check the status of the MySQL daemon, run:
# rcmysql status
If you want to stop the MySQL daemon, run:
# rcmysql stop
Warning! After installation, the MySQL root password is empty by default. It's recommended that you run mysql_secure_installation, a script that helps secure MySQL. When running mysql_secure_installation, you will be prompted to change the MySQL root password, remove anonymous user accounts, disable remote root logins, remove test databases, and reload the privileges table. It is recommended that you answer yes to all of these options and change the root password. Run the following command to execute the script:
After you run, you can login to MySQL:
$ mysql -u root -p
Enter the MySQL root password (which you changed in the previous step) and you'll be presented with a prompt where you can issue SQL statements to interact with the database.
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.
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 system.
To login from another computer, execute the following:
mysql> GRANT ALL ON testdatabase.* TO 'mysqluser'@'<ip-address>' IDENTIFIED BY 'password';
ip-address is the IP address of the computer from which you will connect to MySQL.
To exit the MySQL database administration utility, issue the following command:
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 click the name of your new VM, then click Endpoints.
Click Add Endpoint at the bottom of the page.
Add an endpoint with name "MySQL", protocol TCP, and both Public and Private ports set to "3306". This will allow MySQL to be accessed remotely.
To remotely connect to MySQL running on your OpenSUSE virtual machine in Windows Azure, run the following command on your local computer:
mysql -u mysqluser -p -h <yourservicename>.cloudapp.net
For example, using the virual machine we created in this tutorial, the command would be:
mysql -u mysqluser -p -h testlinuxvm.cloudapp.net
You've successfully configured MySQL, created a database, and a new user. For more information on MySQL, see the MySQL Documentation.
In this tutorial you learned how to create a virtual machine running OpenSUSE Linux and remotely connect to it using SSH or PuTTY. You also learned how to install and configure MySQL on the Linux virtual machine. For more information on MySQL, see the MySQL Documentation.