How to install SQL Server on CentOS 7

Share on Social Media

Learn how to install SQL Server on CentOS 7 with our comprehensive step-by-step guide. Follow detailed instructions for a smooth installation and configuration of SQL Server on your CentOS 7 system. #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.

How to install SQL Server on CentOS 7
How to install SQL Server on CentOS 7

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

Recommended Training: Complete Microsoft SQL Server Database Administration Course from Abbas Mehmood

3832968 141a 3
show?id=oLRJ54lcVEg&bids=1597309

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

Build yum cache as follows:

yum makecache fast

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

Output:

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

Output:

â 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
firewall-cmd --reload

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

Output:

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/

Output:

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:

select name from sys.databases;
go

Output:

name                                                                            
----------------------
master
tempdb
model
msdb

(4 rows affected)

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

create database contacts;
go

Create a table in contacts database.

use contacts;
create table contacts_list (
   contact_id char(6) primary key,
   contact_name char(30));
go

Check our newly created table.

select name from sys.tables;
go

Output:

name                                                                            
-----------------------
contacts_list

(1 rows affected)

Insert a row in contacts_list table.

use contacts;
insert into contacts_list
  values
  ('101','Ahmer M');
go

Output:

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.

quit

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

Frequently Asked Questions (FAQs)

1. Can I install SQL Server on CentOS 7?

Yes, Microsoft provides official support for SQL Server on Linux, including CentOS 7.

2. Do I need a GUI to install SQL Server on CentOS 7?

No, SQL Server can be installed and managed entirely via the command line.

3. What are the system requirements for SQL Server on CentOS 7?

You need at least 2 GB RAM, 6 GB disk space, and a supported version of CentOS 7.

4. How do I start and stop SQL Server after installation?

You can manage the SQL Server service using systemctl commands (e.g., start, stop, restart).

5. Is SQL Server free on CentOS 7?

SQL Server offers a free Developer and Express edition. Other editions require a license.

Final Thoughts

Installing SQL Server on CentOS 7 allows you to combine the power of Microsoft’s relational database engine with the flexibility and stability of a Linux environment. By completing the installation and initial configuration, you now have a solid foundation for developing, testing, or deploying database-driven applications.

Remember to regularly apply updates, configure backups, and monitor performance to ensure your SQL Server instance remains secure, efficient, and reliable. With the setup complete, you’re ready to take full advantage of SQL Server’s capabilities on a CentOS 7 platform.

Need a dependable Linux system administrator? I specialize in managing, optimizing, and securing Linux servers to keep your operations running flawlessly. Check out my services on Fiverr!

Thank you for reading, and best of luck with your SQL Server installation on CentOS 7!

Looking for something?

2 responses to “How to install SQL Server on CentOS 7”

  1. Unknown Avatar

    anyway to enter yes to agree to the license without stopping my setup script?

    already tried without success:
    yes "YES" | rpm -i msodbcsql17-17.4.2.1-1.x86_64.rpm
    echo -e 'YES' | rpm -i msodbcsql17-17.4.2.1-1.x86_64.rpm

Leave a Reply

Available for Amazon Prime