How to Install SQL Server on Linux

As from SQL Server 2017, we now have support for running our favorite RDMS on Linux, as well as Windows!

This guide walks you through installing SQL Server 2019 on Red Hat Linux, setting up command-line tools, and connecting both locally and remotely. Hope it helps!

Topics Included:
1. Installing SQL Server on Linux
2. Installing the SQL Server Command-Line Tools
3. Connecting to SQL Server from Linux


1. Installing SQL Server on Linux

First, ensure your system is up to date:

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

Step 1: Add the SQL Server Repository
Download and configure the Microsoft SQL Server 2019 repository for Red Hat:

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

Step 2: Install SQL Server
Run the following command to install SQL Server:

sudo yum install -y mssql-server
Linux Yum Install SQL Server

Step 3: Configure SQL Server
Once installed, run the setup tool to choose the edition, set the SA (System Administrator) password, and accept the license agreement:

sudo /opt/mssql/bin/mssql-conf setup
Linux MSSQL Configuration

Step 4: Verify SQL Server is Running
Check the service status to confirm that SQL Server is up and running:

systemctl status mssql-server
Linux Systemctl Status MSSQL

If it’s not running, start the service, and we should ensure SQL Server is enabled for start at boot:

sudo systemctl start mssql-server
sudo systemctl enable mssql-server

Step 5: Allow Remote Connections
To install firewalld which I’m using here, you can follow my other guide: How to Install Firewalld on Linux

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

2. Installing the SQL Server Command-Line Tools

The command-line tools (SQLCMD & BCP) allow you to interact with SQL Server from the terminal.

Step 1: Add the Microsoft Repository
Download and configure the Microsoft Red Hat repo:

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

Step 2: Install SQL Server Command-Line Tools
Run the following command to install the ODBC driver for SQL Server on Linux:

sudo yum install -y mssql-tools unixODBC-devel
Linux Install SQL Server ODBC Driver

Step 3: Add SQL Server Tools to PATH
To use sqlcmd and bcp without specifying the full path, update 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
Linux Add MSSQL-Tools to PATH

3. Connecting to SQL Server from Linux

Once you have SQL Server along with the command-line tools installed, we can connect using sqlcmd by running the following:

sqlcmd -S localhost -U SA -P '<YourStrongPassword>'
Linux SQLCMD Select Sys.Tables

If connected successfully, you’ll see a 1> prompt, indicating the SQL environment is ready.

Alternatively we can be connecting from a Windows computer running SSMS:

SSMS Connect to AWS EC2 Linux SQL Server


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Error Messages (5) Failover Cluster Instances (FCI) (1) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Administration (2) Logging & Monitoring (1) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (2) SQL Certificates & Encryption (3) SQL Server Agent (5) SQL Server CDC (2) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (16) SQL Server Networking (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance Tuning (6) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) SQL Server Security (4) SQL Server Storage (10) Windows Admin (21) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)