How to provision a Linux SQL Server Virtual Machine in Azure

You’re an existing SQL Server customer and are looking to explore the fast-growing Linux operating system. Whether on-premises or in the cloud, Microsoft has you covered. With SQL Server 2017, and now SQL Server 2019, SQL Server is available on Red Hat Enterprise Linux, SUSE Linux Enterprise Server, and Ubuntu.

For our purposes, I’m going to walk through how to use the Azure portal to create a Linux virtual machine with SQL Server 2017 or 2019 installed. If you’re following along, you’ll need an Azure subscription. If you don’t already have one, sign up for an Azure free account. Alternatively, if you know which options you’re going to select, you can create a Linux virtual machine with the Azure command-line interface. Or, if you want to learn more about the benefits of SQL Server in Azure, download Future-Proof Your Data Infrastructure with Azure: A Business Case for Database Administrators.

First, we’ll create a Linux virtual machine with SQL Server installed:

  1. Sign in to the Azure portal.
  2. Select Create a resource, and then Compute.
  3. Next to the Featured heading, select See all.
  4. In the search box, type SQL Server 2019, and select Enter.
  5. You can limit the search results by operating system. To do so, select Operating system > Red Hat.
  6. Select a SQL Server 2019 image from the search results.
  7. Select Create.

The next step is to set up your Linux virtual machine:

  1. In the Basics tab, select your Subscription and Resource Group.
  2. In virtual machine name, enter a name for your new Linux virtual machine.
  3. Type or select the following, based on your requirements such as region, availability options, and change size.
  4. For authentication type, select SSH public key. (SSH is more secure than a password.)
  5. For username, enter the administrator’s name.
  6. For SSH public key, enter your Rivest–Shamir–Adleman (RSA) public key.
  7. For public inbound ports, choose allow selected ports and choose the SSH (22) port in the select public inbound ports.
  8. You can change or keep the default settings for disks, networking, management, guest configuration, and tags.
  9. Select Review and Create, and then select Create.

Next, connect to the Linux virtual machine. If you use a BASH shell, connect to the Azure virtual machine using the SSH command. In the following command, replace the virtual machine username and IP address to connect to your Linux virtual machine, and you can find the IP address of your virtual machine in the Azure portal:

ssh azureadmin@40.55.55.555

If you don’t have a BASH shell, install an SSH client like PuTTY.

The new virtual machine installs SQL Server with a random system administrator (SA) password, so you’ll need to reset the password before connecting to SQL Server with the system administrator login:

  1. After connecting to the Linux virtual machine, open a new command terminal.
  2. Change the system administrator password with the following commands:

sudo systemctl stop mssql-server

sudo /opt/mssql/bin/mssql-conf set-sa-password

When prompted, enter a new system administrator password and password confirmation.

  1. Finally, restart the SQL Server service:

sudo systemctl start mssql-server

You’ve just provisioned a SQL Server 2017 virtual machine in Azure! You can connect to it locally with sqlcmd to run Transact-SQL queries or you can configure the Azure virtual machine for remote SQL Server connections. The best part is, you now have a full version of SQL Server in the cloud. There’s no need to manage on-premises hardware or secure the budget to procure and manage that hardware. Plus, the images are pay-as-you-go, so you only pay for what you use.

To learn more about moving your databases to the cloud, download Future-Proof Your Data Infrastructure with Azure: A Business Case for Database Administrators or check out the SQL Server on RHEL Azure VMs Operations Guide.