Databases

Run Microsoft SQL Server 2019 on Rocky 8 / RHEL 8

This guide will walk you through the installation of Microsoft SQL Server (MS SQL) on RHEL / CentOS 8. MS SQL is a relational database system by Microsoft that was open-sourced in 2016. Starting with SQL Server 2017, it is available for production workloads on RHEL and other Linux distributions.

Original content from computingforgeeks.com - post 12024

The release of MS SQL Server available for production workloads is MS SQL 2017 and MS SQL 2019. Follow the steps in the next sections to install and run Microsoft SQL Server (MS SQL) 2019 on RHEL / Rocky Linux 8 Linux server.

Below are the minimum system requirements to run MS SQL Server 2019:

  • Minimum memory of 3 GB
  • CPU processor with a minimum speed of 1.4 GHz. But the recommended is >= 2 GHz
  • SQL Server requires a minimum of 10 GB of available hard-disk space

Step 1: Add Microsoft SQL Server 2019 repo

The Microsoft SQL database server packages are available on Red Hat repository which needs to be added manually.

sudo curl https://packages.microsoft.com/config/rhel/8/mssql-server-2019.repo -o /etc/yum.repos.d/mssql-server-2019.repo 
sudo  curl https://packages.microsoft.com/config/rhel/8/prod.repo -o /etc/yum.repos.d/msprod.repo

Step 2: Install MS SQL server

All the packages required for Microsoft SQL Server 2019 are available on the repositories added. Just execute the commands below to install MS SQL server.

sudo dnf -y install mssql-server

Dependency tree:

...                                                           
Transaction Summary
======================================================================================================================================================================================================
Install  17 Packages

Total download size: 306 M
Installed size: 1.3 G

Accept License Agreement when you see a prompt:

The license terms for this product can be downloaded from
https://aka.ms/odbc17eula and found in
/usr/share/doc/msodbcsql17/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
YES

Step 3: Install SQL server CLI tools

Then install mssql-tools with the unixODBC developer package.

sudo yum -y install mssql-tools unixODBC-devel 

Accept License:

Do you accept the license terms? (Enter YES or NO)
YES
...
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746949 and found in
/usr/share/doc/mssql-tools/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
YES

Confirm installation.

$ rpm -qi mssql-server
Name        : mssql-server
Version     : 15.0.4375.4
Release     : 1
Architecture: x86_64
Install Date: Thu 11 Jul 2024 08:41:47 AM UTC
Group       : Unspecified
Size        : 1179608143
License     : Commercial
Signature   : RSA/SHA256, Tue 11 Jun 2024 07:54:08 AM UTC, Key ID eb3e94adbe1229cf
Source RPM  : mssql-server-15.0.4375.4-1.src.rpm
Build Date  : Tue 11 Jun 2024 07:22:45 AM UTC
Build Host  : ed44a210c000000.uul5buiem4oevegna5wrrtrsyf.phxx.internal.cloudapp.net
Relocations : (not relocatable)
Summary     : Microsoft SQL Server Relational Database Engine
Description :
....

$ rpm -qi mssql-tools 
Name        : mssql-tools
Version     : 17.10.1.1
Release     : 1
Architecture: x86_64
Install Date: Thu 11 Jul 2024 08:43:43 AM UTC
Group       : Applications/Driver
Size        : 730887
License     : http://go.microsoft.com/fwlink/?LinkId=746949
Signature   : RSA/SHA256, Tue 28 Jun 2022 05:34:58 PM UTC, Key ID eb3e94adbe1229cf
Source RPM  : mssql-tools-17.10.1.1-1.src.rpm
Build Date  : Thu 23 Jun 2022 09:23:42 PM UTC
Build Host  :
Relocations : (not relocatable)
Packager    : Microsoft SQL Tools Team <[email protected]>
Summary     : Tools for Microsoft(R) SQL Server (R)
....

Step 4: Initialize MS SQL Database Engine

After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

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

1. Select an edition you’d like to use

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)
  7) Enterprise Core (PAID)
  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): 2

For me. I’ll go with 2 – Developer (free, no production use rights).

2. Accept the license terms

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

3. Set SQL Server system administrator password:

Enter the SQL Server system administrator password: <Password>
Confirm the SQL Server system administrator password: <Confirm-Password>
Configuring SQL Server... 

ForceFlush is enabled for this instance. 
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

The service should be started and set to start at boot.

$ 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  Tue 2024-05-17 13:10:00 EAT; 29s ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 8699 (sqlservr)
Tasks: 157
Memory: 727.2M
CGroup: /system.slice/mssql-server.service
├─8699 /opt/mssql/bin/sqlservr
└─8727 /opt/mssql/bin/sqlservr
May 17 13:10:03 cent8.novalocal sqlservr[8699]: [61B blob data]
May 17 13:10:03 cent8.novalocal sqlservr[8699]: [96B blob data]
May 17 13:10:03 cent8.novalocal sqlservr[8699]: [66B blob data]

$ systemctl is-enabled mssql-server.service 
enabled

Add /opt/mssql/bin/ to your $PATH variable:

echo 'export PATH=$PATH:/opt/mssql/bin:/opt/mssql-tools/bin' | sudo tee /etc/profile.d/mssql.sh

Source the file to start using MS SQL executable binaries in your current shell session:

source /etc/profile.d/mssql.sh

If you have an active Firewalld service, allow SQL Server ports for remote hosts to connect:

sudo firewall-cmd --add-port=1433/tcp --permanent
sudo firewall-cmd --reload

Step 5: Test SQL Server

Connect to the SQL Server and verify it is working.

sqlcmd -S localhost -U SA

Authenticate with the password set in Step 4.

Show Database users:

1> select name from sysusers;
2> go
name
MS_AgentSigningCertificate##
MS_PolicyEventProcessingLogin##
db_accessadmin
db_backupoperator
db_datareader
db_datawriter
db_ddladmin
db_denydatareader
db_denydatawriter
db_owner
db_securityadmin
dbo
guest
INFORMATION_SCHEMA
public
sys
(16 rows affected)
1>

Create a test database:

CREATE DATABASE mytestDB
SELECT Name from sys.Databases
GO
USE mytestDB
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
GO
SELECT * FROM Inventory LIMIT 1;

Show databases on the SQL Server.

1> select name,database_id from sys.databases; 
2> go
name          database_id
------------- -----------
master                  1
tempdb                  2
model                   3
msdb                    4
testDB                  5
(5 rows affected)

Drop a database:

1> DROP DATABASE testDB;
2> GO

Installation of SQL Server on other Linux systems:

Related Articles

CentOS Run Rocky Linux 10 / AlmaLinux 10 VMs with Vagrant and VirtualBox RHEl Install Ejabberd XMPP Server on CentOS 8 | RHEL 8 AlmaLinux Install Java 21 LTS (OpenJDK 21) on AlmaLinux | CentOS | RHEL 10 Databases Manage MySQL / PostgreSQL / SQL Server using SQLPad Editor

Leave a Comment

Press ESC to close