Published on

May 11, 2020

Installing SQL Server on Linux: A Step-by-Step Guide

Microsoft has made significant strides in expanding the capabilities of SQL Server, including the ability to run it on Linux. In this article, we will walk you through the process of installing SQL Server on Linux, specifically on an Azure VM using the Azure Cloud Shell.

Prerequisites

Before we begin, make sure you have the following:

  • An Azure subscription
  • Basic Linux command knowledge
  • Basic Azure portal knowledge

Step 1: Provisioning the Azure VM

First, you need to spin up a Linux VM on Azure. You can follow the step-by-step process outlined in the Azure Portal walkthrough to create your VM. Make sure you choose a Linux distribution that is supported by SQL Server, such as Ubuntu 16.04 or 18.04.

Step 2: Logging into the VM

Once your VM is up and running, you can use the Azure Cloud Shell to log into the VM. Launch the shell from the Azure portal and open the code editor, which is a Visual Studio Code console. Change to the directory with the SSH keys and use the SSH command to connect to the VM.

ssh -i ~/.ssh/id_rsa username@public_ip_address

Make sure to replace “username” with your username and “public_ip_address” with the public IP address of your VM. You can verify that you have successfully logged in by running a basic ‘hostname’ command.

Step 3: Installing SQL Server 2019

Now that you are logged into the VM, you can begin the SQL Server 2019 installation. Start by adding the GPG key and updating your software:

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –
sudo apt-get update

Next, register the Microsoft SQL Server Ubuntu repository for SQL Server 2019:

sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"

Finally, install SQL Server with a single command:

sudo apt-get install -y mssql-server

During the installation, you will be prompted to set a strong password for the ‘sa’ account. Make sure to follow the password requirements.

Step 4: Completing the Configuration

To complete the SQL Server setup, run the following command:

sudo /opt/mssql/bin/mssql-conf setup

This will launch a menu of configuration options. Select the desired edition (e.g., Developer Edition) and provide a strong password for the ‘sa’ account.

Step 5: Checking the Status

After the setup is complete, you can check the status of the SQL Server service using the systemctl command:

systemctl status mssql-server

If the server is running, you should see the status as ‘Active (running)’.

Step 6: Installing SQL Server Tools

By default, the SQL Server tools are not installed. To install them, import the public repository’s GPG keys:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –

Next, register the Microsoft Ubuntu repository:

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Update the sources list and install the unixODBC developer package:

sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev

Optionally, you can add the SQL Server tools to your PATH environment variable:

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

Now you have successfully installed SQL Server and the SQL Server tools.

Step 7: Testing the Installation

To test the installation, you can use the sqlcmd utility to connect to SQL Server and run a basic command. Open a new terminal and run the following command:

sqlcmd -S localhost -U SA -P <yoursapassword>
SELECT name FROM sys.databases
GO

If everything is set up correctly, you should see the names of the databases in the output.

Step 8: Configuring Network Access

If you want to access SQL Server from outside the VM, you need to open the port 1433 for inbound traffic. In the Azure portal, navigate to the Networking section of your VM and add an inbound rule for port 1433.

Conclusion

With the availability of SQL Server on Linux, Microsoft has made it easier for organizations running Linux VMs to leverage the power of SQL Server. As a SQL Server DBA, it is worth exploring and experimenting with SQL Server on Linux to expand your skillset.

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.