How to install SQL Server on CentOS 7

Share on Social Media

In this guide, you will learn, how to install SQL Server on CentOS 7 or other Redhat based Linux OS. #centlinux #linux #sqlserver

What is SQL Server? :

SQL Server is a Relational Database Management System (RDBMS) developed by Microsoft. Since it’s inception in 1989 from Sybase SQL Server, MS SQL Server was a platform dependent RDBMS and it only support different versions of Microsoft Windows. However, Microsoft added support for Linux platform in MS SQL Server 2017. Therefore, we can now install MS SQL Server 2017 (or later) on Windows, Linux and Docker platforms.

MS SQL Server 2017 is the stable version that is currently available to download. However, a MS SQL Server 2019 version is also available at their preview yum repository.

In this article, we will install SQL Server on CentOS 7 machine and then we will create a test database and a table using Transact-SQL (T-SQL).

This article only addresses the installation of MS SQL Server 2019 on CentOS 7 and some basic commands to give you an introduction of the environment. Therefore, if you are willing to know more about MS SQL Server and Transact-SQL (T-SQL) then you should read Microsoft SQL Server 2019: A Beginner’s Guide (PAID LINK) by Dusan Petkovic.

System Specification:

We have provisioned a CentOS 7 virtual machine with following specifications:

  • Hostname – sqlserver-01.centlinux.com
  • IP Address – 192.168.116.157/24
  • Operating System – CentOS 7.6
  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 60 GB

Install SQL Server on CentOS 7:

Connect to sqlserver-01.centlinux.com using ssh as root user.

Download and add MS SQL Server 2019 (Preview) yum repository.

# curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-preview.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   240  100   240    0     0     62      0  0:00:03  0:00:03 --:--:--    62

Build yum cache as follows:

# yum makecache fast
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.ges.net.pk
 * extras: mirrors.ges.net.pk
 * updates: mirrors.ges.net.pk
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
packages-microsoft-com-mssql-server-preview              | 2.9 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/3): extras/7/x86_64/primary_db                          | 187 kB   00:03
(2/3): packages-microsoft-com-mssql-server-preview/primary |  68 kB   00:04
(3/3): updates/7/x86_64/primary_db                         | 3.4 MB   00:11
Metadata Cache Created

Install SQL Server on CentOS 7 using yum command.

# yum install -y mssql-server

After installation of your RDBMS software, run setup as suggested by yum installer above.

# /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.

Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409

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):

Select your required MS SQL Server edition. We are installing Developer Edition here.

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]:

You can view the License and Privacy statments in a browser. Read and Agree with License terms to continue.

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

Enter the SQL Server system administrator password:

Set a Strong System Administrator (SA) Password for MS SQL Server Instance.

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

This is an evaluation version.  There are [167] 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.

Check status of Database Service.

# systemctl status mssql-server.service
â 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-04-10 20:51:55 PKT; 13h ago
     Docs: https://docs.microsoft.com/en-us/sql/linux
 Main PID: 7763 (sqlservr)
   CGroup: /system.slice/mssql-server.service
           ââ7763 /opt/mssql/bin/sqlservr
           ââ7785 /opt/mssql/bin/sqlservr

Apr 10 20:52:30 sqlserver-01.centlinux.com sqlservr[7763]: 2019-04-10 20:52:30....
Apr 11 09:14:38 sqlserver-01.centlinux.com sqlservr[7763]: 2019-04-11 09:14:38....
Hint: Some lines were ellipsized, use -l to show in full.

To allow remote connections, we have to allow the MS SQL Server default port 1433/tcp in Linux Firewall.

# firewall-cmd --permanent --add-port=1433/tcp
success
# firewall-cmd --reload
success

Install SQL Server Tools on CentOS 7:

We have configured a MS SQL Server 2019 and we can use SQL Server Management Studio (SSMS) on a windows based client to connect and use our database server.

However, we are also installing MS SQL Server command line utilities, so we can perform database administration tasks directly on our database server.

Download and install Microsoft yum repository to install SQL Server tools.

# curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

Build yum cache for the newly added yum repository.

# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ges.net.pk
 * extras: mirrors.ges.net.pk
 * updates: mirrors.ges.net.pk
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
packages-microsoft-com-mssql-server-preview              | 2.9 kB     00:00
packages-microsoft-com-prod                              | 2.9 kB     00:00
updates                                                  | 3.4 kB     00:00
packages-microsoft-com-prod/primary_db                     | 164 kB   00:01
Metadata Cache Created

Install SQL Server Tools using yum command.

# yum install -y mssql-tools

SQL Server tools has been installed in /opt/mssql/bin/ directory.

# ls /opt/mssql-tools/bin/
bcp  sqlcmd

Add this directory to PATH environment variable for accessibility and convenience.

# cat > /etc/profile.d/mssql-tools.sh << EOF
> #!/bin/bash
> export PATH=$PATH:/opt/mssql-tools/bin
> EOF

SQL Server tools has been installed on CentOS 7.

Execute Transact-SQL Commands:

Connect to MS SQL Server instance using SA user and password.

# sqlcmd -S localhost -U SA -P 'Ahmer@1234'

You are now at the Transact-SQL (T-SQL) command prompt. Execute a query as follows:

1> select name from sys.databases;
2> go
name                                                                            
----------------------
master                                                                          
tempdb                                                                          
model                                                                           
msdb                                                                            

(4 rows affected)

Now, create a custom database on our MS SQL Server 2019 instance.

1> create database contacts;
2> go

Create a table in contacts database.

1> use contacts;
2> create table contacts_list
3> (contact_id char(6) primary key,
4> contact_name char(30));
5> go
Changed database context to 'contacts'.

Check our newly created table.

1> select name from sys.tables;
2> go
name                                                                            
-----------------------
contacts_list                                                                   

(1 rows affected)

Insert a row in contacts_list table.

1> use contacts;
2> insert into contacts_list
3> values
4> ('101','Ahmer M');
5> go
Changed database context to 'contacts'.

(1 rows affected)

You can execute any Transact-SQL (T-SQL) commands using sqlcmd. But we are not showing every command here in this article to keep it brief.

Exit from Transact-SQL (T-SQL) command prompt.

1> quit

We have successfully configured MS SQL Server 2019 on CentOS 7.

Conclusion:

In this guide, you have learned, how to install SQL Server on CentOS 7 or other Redhat based Linux OS.

Scroll to Top