Installing SQL Server on Linux

A post on installing SQL Server on Linux, following the Microsoft SQL Server 2019 Guide (Red Hat).

> 1. Install SQL Server.
> 2. Install the SQL Server Command-Line Tools.
> 3. Connect to SQL Server Locally.
> 4. Connect to SQL Server Remotely.

1. Install SQL Server

1. Get connected & 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
Linux EC2 Connect Curl MSSQL 2019

2. Install SQL Server.

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

3. Run mssql-conf setup to choose the SQL Server Edition, SA password and accepting of the Licence Agreement.

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

4. Check the SQL Server service by running systemctl status.

systemctl status mssql-server
Linux Systemctl Status MSSQL

5. Allow in remote 1433 connections.

I’m using Firewalld as per Microsoft’s guide – here’s my quick install notes.

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

2. Install the SQL Server Command-Line Tools

1. Download the Microsoft Red Hat repo config file.

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

2. Install ODBC driver for SQL Server (Linux) – allows BCP & SQLCMD.

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

3. Add mssql-tools to PATH environment variable – allows tools to be run without full path.

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. Connect to SQL Server Locally

Using the PATH variable above, call sqlcmd:

Linux SQLCMD Select Sys.Tables

4. Connect to SQL Server Remotely

I’m connecting to the EC2 Amazon Linux SQL Server instance via SSMS on my local machine (Windows 10).

For this to work we had to allow in remote 1433 connections (step 5 during install above), and I added my IP into the AWS Security Group.

SSMS Connect to AWS EC2 Linux SQL Server

Comments

Leave a Reply

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