How to Install Microsoft SQL Server on CentOS 8
Microsoft provides the MSSQL Server for different Linux distros such as Ubuntu, Debian, RHEL/CentOS, and Suse. This tutorial will show you how to install the Microsoft SQL Server 2019 and the MSSQL Tools on the CentOS 8 system.
System Requirements:
- CentOS 8 System
- 4GB or more RAM
- Root privileges
What we will do:
- Install Python2
- Add MSSQL Repository
- Install MSSQL Server
- Install and Configure MSSQL Tools
- Testing
Step 1 - Install Python2
First, we will install the python2 package to CentOS 8 server. By default, the AppStream repository provides multiple python versions.
The MSSQL Server needs the python2 for its dependencies.
Install python2 using the dnf command below.
dnf install python2
Once the installation is complete, set the python2 as a default python.
sudo alternatives --config python
Now check the python command below.
python --version
You will see default python on the CentOS 8 server is "python2".
Step 2 - Add MSSQL Repository
In this first step, we're going to add the official MSSQL repository to the CentOS 8 system.
Download the MSSQL repository configuration to the '/etc/yum.repos.d/' directory using the following command.
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo
After that, check all available repository on the system using the command below.
sudo dnf repolist
And you will be shown the MSSQL repository has been added to the CentOS 8 Server.
Step 3 - Install MSSQL Server
Download the MSSQL Server rpm packages using the dnf command below.
dnf download mssql-server
Once it's downloaded, install the rpm package using the following command.
sudo rpm -Uvh --nodeps mssql-server*rpm
And you will get the result as below.
Next, we need to set up our MSSQL Server installation by using the 'mssql-conf' command below.
sudo /opt/mssql/bin/mssql-conf setup
Choose number 2 for the MSSQL Developer version, type 'YES' for the license agreement, and then type your strong password for the MSSQL Server Login.
Now the MSSQL Server is up and running, you can check the service using the system command below.
systemctl status mssql-server
And you will get MSSQL Server is active and running.
Next, add the MSSQL port '1433' to the firewalld rule.
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload
And the MSSQL Server installation on CentOS 8 has been completed.
Step 4 - Install and Configure MSSQL Tools
In this step, we're going to install the MSSQL tools that will be used as a client to connect to the MSSQL Server.
Firstly, we need to add the MSSQL Tools to the system.
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
Now install the MSSQL Tools using the dnf command as below.
sudo dnf install -y mssql-tools unixODBC-devel
During the installation, you will be asked for the license of these packages.
Type "Yes" to install those packages.
Once the installation is complete, we need to add the MSSQL Tools binary directory to the system '$PATH' variable.
Add the MSSQL Tools bin directory to the '$PATH' environment variable through the '~/.bashrc' and '~/.bash_profile' configuration file.
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
And reload the '~/.bashrc' file.
source ~/.bashrc
After that, check the '$PATH' variable using the following command.
echo $PATH
And you will get the MSSQL Tools binary directory has been added to the '$PATH' variable.
Step 5 - Testing
To test the MSSQL Server installation, we're going to use the 'sqlcmd' command to connect to the MSSQL Server and create a new database on it.
Login to the MSSQL Server using the 'sqlcmd' command below.
sqlcmd -S localhost -U SA
Password:
Type your strong password.
Once you've logged to the MSSQL Server, create a new database 'hakaseDB'.
create database hakaseDB
After that, check the database using the MSSQL queries below.
select name from sys.databases
go
And you will be shown the 'hakaseDB' database has been created.
As a result, the MSSQL Server installation on CentOS 8 Server has been completed successfully.