Install MySQL on a virtual machine running OpenSUSE Linux in Azure

MySQL is a popular, open-source SQL database. This tutorial shows you how to create a virtual machine running OpenSUSE Linux, then install MySQL.

Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account. Just click the Copy button to copy the code, paste it into the Cloud Shell, and then press enter to run it. There are a few ways to launch the Cloud Shell:

Click Try It in the upper right corner of a code block. Cloud Shell in this article
Open Cloud Shell in your browser.
Click the Cloud Shell button on the menu in the upper right of the Azure portal. Cloud Shell in the portal

If you choose to install and use the CLI locally, you need Azure CLI version 2.0 or later. To find the version, run az --version. If you need to install or upgrade, see Install Azure CLI 2.0.

Create a virtual machine running OpenSUSE Linux

First, create a resource group. In this example, we are naming the resource group mySQSUSEResourceGroup and creating it in the East US region.

az group create --name mySQLSUSEResourceGroup --location eastus

Create the VM. In this example, we are naming the VM myVM. We are also going to use a VM size Standard_D2s_v3, but you should choose the VM size you think is most appropriate for your workload.

az vm create --resource-group mySQLSUSEResourceGroup \
   --name myVM \
   --image openSUSE-Leap \
   --size Standard_D2s_v3 \

You also need to add a rule to the network security group to allow traffic over port 3306 for MySQL.

az vm open-port --port 3306 --resource-group mySQLSUSEResourceGroup --name myVM

Connect to the VM

You'll use SSH to connect to the VM. In this example, the public IP address of the VM is You can see the IP address in the output when you created the VM.


Update the VM

After you're connected to the VM, install system updates and patches.

sudo zypper update

Follow the prompts to update your VM.

Install MySQL

Install the MySQL in the VM over SSH. Reply to prompts as appropriate.

sudo zypper install mysql

Set MySQL to start when the system boots.

sudo systemctl enable mysql

Verify that MySQL is enabled.

systemctl is-enabled mysql

This should return: enabled.

MySQL password

After installation, the MySQL root password is empty by default. Run the mysql_secure_installation script to secure MySQL. The script prompts you to change the MySQL root password, remove anonymous user accounts, disable remote root logins, remove test databases, and reload the privileges table.


Log in to MySQL

You can now log in and enter the MySQL prompt.

mysql -u root -p

This switches you to the MySQL prompt where you can issue SQL statements to interact with the database.

Now, create a new MySQL user.

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

The semi-colon (;) at the end of the line is crucial for ending the command.

Create a database

Create a database and grant the mysqluser user permissions.

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

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.

Enable log in from another computer. In this example, the IP address of the computer that we want to log in from is

GRANT ALL ON testdatabase.* TO 'mysqluser'@'' IDENTIFIED BY 'password';

To exit the MySQL database administration utility, type:


Next steps

For details about MySQL, see the MySQL Documentation.