Provision a Linux SQL Server virtual machine in the Azure portal
In this quick start tutorial, you use the Azure portal to create a Linux virtual machine with SQL Server 2017 installed.
In this tutorial, you will:
- Create a Linux SQL VM from the gallery
- Connect to the new VM with ssh
- Change the SA password
- Configure for remote connections
If you don't have an Azure subscription, create a free account before you begin.
Create a Linux VM with SQL Server installed
Sign in to the Azure portal.
In the left pane, click New.
In the New pane, click Compute.
Click See all next to the Featured heading.
In the search box, type SQL Server 2017, and press Enter to start the search.
Click the Filter icon, limit the search to Linux based, Microsoft images, and then click Done.
Select a SQL Server 2017 Linux image from the search results. This tutorial uses Free SQL Server License: SQL Server 2017 Developer on Red Hat Enterprise Linux 7.4.
The Developer edition enables you to test or develop with the features of the Enterprise edition but no SQL Server licensing costs. You only pay for the cost of running the Linux VM.
In the Basics window, fill in the details for your Linux VM.
You have the choice of using an SSH public key or a Password for authentication. SSH is more secure. For instructions on how to generate an SSH key, see Create SSH keys on Linux and Mac for Linux VMs in Azure.
In the Size window, choose a machine size. To see other sizes, select View all. For more information about VM machine sizes, see Linux VM sizes.
For development and functional testing, we recommend a VM size of DS2 or higher. For performance testing, use DS13 or higher.
In the Settings window, you can make changes to the settings or keep the default settings.
On the Summary page, click Purchase to create the VM.
Connect to the Linux VM
If you already use a BASH shell, connect to the Azure VM using the ssh command. In the following command, replace the VM user name and IP address to connect to your Linux VM.
You can find the IP address of your VM in the Azure portal.
If you are running on Windows and do not have a BASH shell, you can install an SSH client, such as PuTTY.
On the PuTTY configuration screen, enter your VM's public IP address.
Click Open and enter your username and password at the prompts.
For more information about connecting to Linux VMs, see Create a Linux VM on Azure using the Portal.
Change the SA password
The new virtual machine installs SQL Server with a random SA password. You must reset this password before you can connect to SQL Server with the SA login.
After connecting to your Linux VM, open a new command terminal.
Change the SA password with the following commands:
sudo systemctl stop mssql-server sudo /opt/mssql/bin/mssql-conf set-sa-password
Enter a new SA password and password confirmation when prompted.
Restart the SQL Server service.
sudo systemctl start mssql-server
Add the tools to your path (optional)
Several SQL Server packages are installed by default, including the SQL Server command-line Tools package. The tools package contains the sqlcmd and bcp tools. For convenience, you can optionally add the tools path,
/opt/mssql-tools/bin/, to your PATH environment variable.
Run the following commands to modify the PATH for both login sessions and interactive/non-login sessions:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
Configure for remote connections
If you need to remotely connect to SQL Server on the Azure VM, you must configure an inbound rule on the network security group. The rule allows traffic on the port on which SQL Server listens (default of 1433). The following steps show how to use the Azure portal for this step.
In the portal, select Virtual machines, and then select your SQL Server VM.
In the list of properties, select Networking.
In the Networking window, click the Add button under Inbound Port Rules.
In the Service list, select MS SQL.
Click OK to save the rule for your VM.
Open the firewall on RHEL
This tutorial directed you to create a Red Hat Enterprise Linux (RHEL) VM. If you want to connect remotely to RHEL VMs, you also have to open up port 1433 on the Linux firewall.
Connect to your RHEL VM.
In the BASH shell, run the following commands:
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent sudo firewall-cmd --reload
Now that you have a SQL Server 2017 virtual machine in Azure, you can connect locally with sqlcmd to run Transact-SQL queries.
If you configured the Azure VM for remote SQL Server connections, you should also be able to connect remotely. For an example of how to connect remotely to SQL Server on Linux from Windows, see Use SSMS on Windows to connect to SQL Server on Linux. To connect with Visual Studio Code, see Use Visual Studio Code to create and run Transact-SQL scripts for SQL Server
For more general information about SQL Server on Linux, see the Overview of SQL Server 2017 on Linux. For more information about using SQL Server 2017 Linux virtual machines, see Overview of SQL Server 2017 virtual machines on Azure.