How to install SQL Server on Ubuntu

How to install SQL Server on Ubuntu

Written by Adam. R on Sep 7th, 2021 Views Report Post

System requirements

Microsoft hasn’t stated the full system requirements to install SQL Server on Ubuntu, Red Hat, SUSE and Docker engine, the only thing they noted is that it requires more than 3.25GB of RAM. Listed below will be the basic minimum system hardware requirements to run Ubuntu, adjusted for the RAM and HDD space requirements to run SQL Server on Ubuntu:

CPU: 700Mhz processor (Intel Celeron or better) RAM: 4GB minimum (Ubuntu needs 512MB at minimum) HDD: 5GB for Ubuntu and additional 3GB for SQL Server at minimum


Installation procedure

  1. To begin open your terminal.
  2. It is here where the installation takes place. First, we need to have the public repository’s GPG keys imported by entering the following command:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –
  1. Now you need to insert the root password before completing the step.
  2. After that, we need to have the Microsoft SQL Server’s Ubuntu repository registered. In this step as in previous, you needs to enter the account password before completing the step (but only if 15 minutes from the last action have passed, as this is Ubuntu’s feature to only type the password only once in 15 minutes to make work flow easier).
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
  1. Now we can install SQL Server on Ubuntu by entering the following commands:
sudo apt-get update
sudo apt-get install -y mssql-server

With this, the package is installed. To completely install SQL Server on Ubuntu we need to run the mssql-conf setup and follow the prompts. Also, a strong password is recommended for the creation of SA account (Minimum length of 8 characters, including both uppercase and lowercase letters and base 10 digits or/and non-alphanumeric symbols). To continue the setup run the following command:

sudo /opt/mssql/bin/mssql-conf setup
  1. After the install of SQL Server on Ubuntu has been completed, we can check if the service is started and running by entering the following command:
systemctl status mssql-server
  1. After some time, a software update may be released and that can be handled with a few lines in the Terminal. First, it is needed to update the apt-get repository lists by running the command below and entering the account password.
sudo apt-get update
sudo /opt/mssql/bin/mssql-conf setup
  1. After updating the repository lists, all that is needed to update the SQL Server is to run the above installation command which will update the mssql-server package:
sudo apt-get install mssql-server

Running these commands will try to download the latest package, afterwards replace the updated binaries which are located under /opt/mssql. No user-generated databases or system databases are affected with this operation.


Installation of SQL Server Tools

Optionally, you can install SQL Server Tools on Ubuntu to improve their experience. Currently, the package contains the Command line query utility (sqlcmd) and Bulk import export utility (bcp).

The installation is also done from the Terminal:

  1. First, it is needed to import the public repository’s GPG keys. After running this command, it is necessary to input the account password.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –
  1. After that it is needed to 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
  1. Update the sources list and run the installation command with the unixODBC developer package:
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
  1. After running the second command, you will be prompted to allow the installation
  2. After which you will need to Accept the license terms
  3. For the sqlcmd and bcp commands to be able to get accessed from bash shell, PATH needs to be modified in the ~/.bash_profile using the command:
echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile

For non-login and interactive sessions, the PATH needs to be modified accordingly:

echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bashrc
source ~/.bashrc
  1. After completing the installation, a test database is created to check the functionality of the SQL Server on Ubuntu.
  2. As the process completes, the latest SQL Server Management Studio installed on a Windows machine is started. Since the Ubuntu machine is in the local network, the IP address is 192.168.1.8. in this case. After connecting with SQL Server credentials (as Windows authentication doesn’t work in this case), it can be seen that the database we just created using sqlcmd tool in Linux Terminal is created and the server is reachable.

Installation of SQL Server Agent

In addition to SQL Server Tools, SQL Server Agent can also be installed as an addition after we install SQL Server on Ubuntu to manage and run scheduled jobs.

  1. Update the sources list and run the installation command, after which the Terminal will prompt to restart the SQL Server for the Agent to be able to start.
sudo apt-get update
sudo apt-get install mssql-server-agent
sudo systemctl restart mssql-server

After that, connecting to the server in SSMS shows up that the SQL Server Agent is running.


Troubleshooting

Problem

  • Cannot connect to the SQL Server on Ubuntu from SSMS Answer
  • Verify if the server is running on the Ubuntu machine by running the command:
sudo systemctl status mssql-server

If the server is not running, it can be started by running the command:

sudo systemctl start mssql-server

Verify that the firewall has allowed the port 1433 which SQL Server is using by default. First we need to check the status of the ufw, which is Ubuntu’s Uncomplicated Firewall , by running the following command and entering the password for the account:

sudo ufw status

You should a response of

Status: active

To allow a port through the ufw, run the following command:

sudo ufw allow 1433

Problem

  • Cannot connect to the server using SA account

Solution

  • To reset the system administrator (SA) password, run the following commands:
sudo systemctl stop mssql-server
sudo /opt/mssql/bin/mssql-conf setup

Take note that this will temporarily stop SQL Server mssql-server service.


Comments (0)