Bobcares

Install SQL Server 2019 on Linux – MSSQL on CentOS and Ubuntu

by | Feb 22, 2021

Recently we had a customer who wanted assistance to install SQL Server 2019 on Linux.

Linux system administrators will need to be knowledgeable on MS SQL Server if they want to stay at the top of their game.

As part of our Server Management Services, we assist our customers with several Linux queries.

Today, let us see how our Support Techs install SQL Server 2019 on Linux.

 

Microsoft SQL Server

A relational database management system, Microsoft SQL Server might be the right choice for an RDBMS.

Open-source MySQL and PostgreSQL are typically synonymous with Linux distributions. However, working with MSSQL on Linux is also supported.

In this article, let us see how to install MSSQL Server 2019 on CentOS 7 and Ubuntu 16.04.

 

Install SQL Server 2019 on Linux

In order to begin, our Support Techs suggest having a Server with at least 2GB of memory along with CentOS 7 and Ubuntu 16.04 servers with root access.

a) Installing MSSQL Server 2019 in CentOS 7

  • Step 1: Add MSSQL 2019 Preview Repo

The best practice is to ensure all packages are up to date:

root@centos ~]# yum update -y

Then, we tell the package manager yum where to look for the mssql-server package by adding the appropriate repo:

root@centos ~]# curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-preview.repo
  • Step 2: Install SQL Server

Now that yum is aware of the MSSQL repo, we can use it to install the package:

root@centos ~]# yum install -y mssql-server
  • Step 3: Configure MSSQL Server

Then, we need to configure SQL with a system administrator password and confirm the edition. Here we use the Developer edition, choice 2, as it is free:

root@centos ~]# /opt/mssql/bin/mssql-conf setup
usermod: no changes
Choose an edition of SQL Server:
1) Evaluation (free, no production use rights, 180-day limit)
2) Developer (free, no production use rights)
3) Express (free)
4) Web (PAID)
5) Standard (PAID)
6) Enterprise (PAID) – CPU Core utilization restricted to 20 physical/40 hyperthreaded
7) Enterprise Core (PAID) – CPU Core utilization up to Operating System Maximum
8) I bought a license through a retail sales channel and have a product key to enter.


Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.

Enter your edition(1-8): 2
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855862&clcid=0x409

The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409

Do you accept the license terms? [Yes/No]:Yes

Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
Configuring SQL Server…

This is an evaluation version. There are [116] days left in the evaluation period.
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

Eventually, we verify that the mssql service is running:

root@centos ~]# systemctl status mssql-server

Our output will be similar to this:

mssql-server.service – Microsoft SQL Server Database Engine
Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2019-10-23 20:18:03 EDT; 2min 45s ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 61529 (sqlservr)
CGroup: /system.slice/mssql-server.service
├─61529 /opt/mssql/bin/sqlservr
└─61549 /opt/mssql/bin/sqlservr
  • Step 4 (Optional): Allow Remote Connections

If we want to access the SQL server remotely, we have to open up the SQL Server port:

Firewalls are in place to keep the server safe by limiting access to it.

root@centos ~]# firewall-cmd –zone=public –add-port=1433/tcp –permanent

Once done, we need to reload our firewall rules and verify the port is open:

[root@centos ~]# firewall-cmd –reload
success
root@centos ~]# firewall-cmd –list-ports
1433/tcp
  • Step 5: Add Microsoft Red Hat repository

We need a way to interact with our SQL server. First, let us add another repo so we can use yum to install SQL Server command-line tools

root@centos ~]# curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
  • Step 6: Install and setup MSSQL Server command-line tools

During the installation of these packages, there will be a couple of interactive prompts to accept the license terms:

root@centos ~]# yum install -y mssql-tools unixODBC-devel

For ease of use we can add the path /opt/mssql-tools/bin/ to the PATH variable on the server so that we can execute SQL commands from any location on the server:

root@centos ~]# echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile

root@centos ~]# source ~/.bashrc

Finally, to verify that we can make a connection to SQL Server, run:

root@centos ~]# sqlcmd -S localhost -U SA
Password:
1>

[Couldn’t complete the installation? Contact us now]

 

b) Installing MSSQL Server 2019 in Ubuntu 16.04

  • Step 1: Add MSSQL Server Ubuntu 2019 preview repo

Initially, we update the server packages:

root@ubuntu1604:~# apt-get update -y

Once done, we add the GPG keys for the repository we want to add. It is a way for Linux users to verify the validity of files and confirm they come from trusted sources:

root@ubuntu1604:~# wget -qO- https://packages.microsoft.com/keys/microsoft.asc | apt-key add –

After that we can add the repository:

root@ubuntu1604:~# add-apt-repository “$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-preview.list)”

The repository requires an HTTPS connection. To ensure that apt can connect to the repo, we need to be certain it can connect over https:

root@ubuntu1604:~# apt-get install -y apt-transport-https
  • Step 2: Install MSSQL Server

Now all that is left to do is to make sure apt knows about the new repo and install MSSQL Server:

root@ubuntu1604:~# apt-get update -y
root@ubuntu1604:~# apt-get install -y mssql-server
  • Step 3: Configure MSSQL Server

The configuration step is the same on both CentOS 7 and Ubuntu 16.04. During the process, there will be interactive prompts:

root@ubuntu1604:~# /opt/mssql/bin/mssql-conf setup
usermod: no changes
Choose an edition of SQL Server:
1) Evaluation (free, no production use rights, 180-day limit)
2) Developer (free, no production use rights)
3) Express (free)
4) Web (PAID)
5) Standard (PAID)
6) Enterprise (PAID) – CPU Core utilization restricted to 20 physical/40 hyperthreaded
7) Enterprise Core (PAID) – CPU Core utilization up to Operating System Maximum
8) I bought a license through a retail sales channel and have a product key to enter.


Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.

Enter your edition(1-8): 2
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855862&clcid=0x409

The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409

Do you accept the license terms? [Yes/No]:Yes

Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
Configuring SQL Server…

This is an evaluation version. There are [116] days left in the evaluation period.
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

MSSQL Server should now be running and enabled. In order to verify, we can run:

root@ubuntu1604:~# systemctl status mssql-server –no-pager
* mssql-server.service – Microsoft SQL Server Database Engine
Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-10-24 00:24:23 EDT; 3min 45s ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 19446 (sqlservr)
Tasks: 135
Memory: 548.5M
CPU: 12.499s
CGroup: /system.slice/mssql-server.service
|-19446 /opt/mssql/bin/sqlservr
`-19485 /opt/mssql/bin/sqlservr
  • Step 4: Allow Remote Connections

If we intend to utilize a remote connection to the new SQL Server, it is necessary to open up the SQL Server port.

To keep our firewall interactions succinct, we install ufw:

root@ubuntu1604:~# apt-get install -y ufw

Once done, we have to enable it. We will receive a warning indicating that the SSH connection might be interrupted. If it is disconnected, log back in and continue:

root@ubuntu1604:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
firewall is active and enabled on system startup

Now it is time to allow traffic through to port 1433:

root@ubuntu1604:~# ufw allow 1433
Rule added
Rule added (v6)
  • Step 5: Install and setup MSSQL Server command-line tools

First, we need to add new GPG keys for the repo that contains the MSSQL command-line tools:

root@ubuntu1604:~# curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add –

Then we can add the repository:

root@ubuntu1604:~# curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | tee /etc/apt/sources.list.d/msprod.list

After that, we update apt and install the command line tools:

root@ubuntu1604:~# apt-get update -y
root@ubuntu1604:~# apt-get install -y mssql-tools unixodbc-dev

There should be one or two interactive prompts to accept licenses during installation like this:

Let us make it easy to execute sqlcmd anywhere on the server:

root@ubuntu1604:~# echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile
root@ubuntu1604:~# echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bashrc
root@ubuntu1604:~# source ~/.bashrc

Finally, we verify that we can connect to MSSQL Server locally:

root@ubuntu1604:~# sqlcmd -S localhost -U SA
Password:
1>

[Need help with the installation? We’d be happy to assist]

 

Few common errors while we Install SQL Server 2019 on Linux

  • Error: ” invalid

While registering the Microsoft SQL server ubuntu repository,

root@server:~# add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2019.list)"

We may receive the error:

Error: '' invalid

In order to solve this error we add the following:

root@server:~# wget -qO- https://packages.microsoft.com/keys/microsoft.asc | apt-key add -OK
root@server:~# add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2019.list)"

In addition, we can try using curl and adding the repository manually.

root@server:~# curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2019.list | tee /etc/apt/sources.list.d/mssql-prod.list
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 103 100 103 0 0 306 0 --:--:-- --:--:-- --:--:-- 307
deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/16.04/mssql-server-2019 xenial main
  • sqlcmd: command not found

If we get an error while connecting to the instance using SQL CMD, it might be due to a problem in the installation of the SQL Command Line Tool.

For Example, connecting to SQL Server Instance by

sqlcmd -S localhost -U SA

and getting the error:

“sqlcmd: command not found”.

To solve this we need to link SQL CMD utilities with Ubuntu accessible directory using

sudo ln -sfn /opt/mssql-tools/bin/sqlcmd /usr/bin/sqlcmd

The ln command is to create links between files. The parameters of this command serve different purposes:

s – symbolic: It makes symbolic links instead of hard links.
f – force: It removes existing destination files.
n – no-dereference: It treats LINK_NAME as a normal file if it is a symbolic link to a directory.

Finally, connect to SQL Server Instance again using sql cmd and perform SQL Server commands in the Ubuntu terminal.

[Facing any other error? We are here for you]

 

Conclusion

In this article, we have explained how to install SQL Server 2019 on Linux. Today, we saw how our Support Techs install MSSQL Server 2019 on CentOS 7 and Ubuntu 16.04.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.