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:
Updating the Server
Ensure your server is up to date:
Installing Ms SQL Server 2019
Download the Microsoft SQL Server 2019 Red Hat repository configuration file:
1
| 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
1
| sudo dnf install -y mssql-server
|
Run mssql-conf setup and follow the prompts to set the SA password and choose your edition.
1
| sudo /opt/mssql/bin/mssql-conf setup
|
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| $ 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:
1
| sudo systemctl status mssql-server
|
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| $ 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:
1
2
| sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload
|
Download the Microsoft Red Hat repository configuration file.
1
| 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.
1
| sudo yum install -y mssql-tools unixODBC-devel
|
For convenience, add /opt/mssql-tools/bin/
to your PATH
environment variable.
1
2
3
| 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
)
1
2
| sqlcmd -S <ip_address>,1433 -U SA -P "<YourNewStrong@Passw0rd>"
sqlcmd -S localhost -U SA -P '<YourPassword>'
|
If successful, you should get to a sqlcmd command prompt: 1>
.
Create a new database
On the next line, write a query to return the name of all of the databases on your server:
1
| 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:
Insert data
Create new table named Inventory:
1
| CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
|
Insert data into the new table:
1
| INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
|
Type GO
to execute the previous commands:
Select data
1
2
| SELECT * FROM Inventory WHERE quantity > 152;
GO
|
To end your sqlcmd session, type QUIT
:
Conclusion
In this guide, we managed to install Ms SQL Server 2019 in Rocky Linux/Alma Linux 8.