Linux

How to install Mssql server on Rocky Linux 8/Centos 8

Pinterest LinkedIn Tumblr

Microsoft SQL Server is a relational database management system developed by Microsoft. It is aimed to be used to store and retrieve data by applications. It can be run either on the same computer or on another across a network.

In this guide we are going to install Microsoft Server 2019 in Rocky Linux/Alma Linux 8 or any RHEL based server. We then connect with sqlcmd to create your first database and run queries.

Also Check:

Table of Contet

  1. Updating the server
  2. Installing Ms SQL Server 2019
  3. Install the SQL Server command-line tools
  4. Connecting locally

Updating the Server

Ensure your server is up to date:

sudo dnf -y update

Installing Ms SQL Server 2019

Download the Microsoft SQL Server 2019 Red Hat repository configuration file:

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

Then use this command to install the server

sudo dnf install -y mssql-server

Run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

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

Output:

$ sudo /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=2109348&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): 3
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=2104294&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...

The licensing PID was successfully processed. The new edition is [Express Edition].
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.

Once the configuration is done, verify that the service is running:

sudo systemctl status mssql-server

Output:

$ sudo systemctl status mssql-server
● 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 Thu 2021-08-05 10:31:20 UTC; 31s ago
     Docs: https://docs.microsoft.com/en-us/sql/linux
 Main PID: 70366 (sqlservr)
    Tasks: 131
   Memory: 677.2M
   CGroup: /system.slice/mssql-server.service
           ├─70366 /opt/mssql/bin/sqlservr
           └─70393 /opt/mssql/bin/sqlservr

Aug 05 10:31:26 prod-db sqlservr[70366]: [318B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [78B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [84B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [145B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [96B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [66B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [96B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [100B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [71B blob data]
Aug 05 10:31:26 prod-db sqlservr[70366]: [124B blob data]

To allow remote connections, open the SQL Server port on the firewall on RHEL. The default SQL Server port is TCP 1433. If you are using FirewallD for your firewall, you can use the following commands:

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

Install the SQL Server command-line tools

Download the Microsoft Red Hat repository configuration file.

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

Run the following commands to install mssql-tools with the unixODBC developer package.

sudo yum install -y mssql-tools unixODBC-devel

For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable.

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

Connecting locally

Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P)

sqlcmd -S <ip_address>,1433 -U SA -P "<[email protected]>"
sqlcmd -S localhost -U SA -P '<YourPassword>'

If successful, you should get to a sqlcmd command prompt: 1>.

Create a new database

CREATE DATABASE TestDB

On the next line, write a query to return the name of all of the databases on your server:

SELECT Name from sys.Databases

The previous two commands were not executed immediately. You must type GO on a new line to execute the previous commands:

GO

Insert data

USE TestDB

Create new table named Inventory:

CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)

Insert data into the new table:

INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);

Type GO to execute the previous commands:

GO

Select data

SELECT * FROM Inventory WHERE quantity > 152;
GO

To end your sqlcmd session, type QUIT:

QUIT

Conclusion

In this guide, we managed to install Ms SQL Server 2019 in Rocky Linux/Centos 8

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment