Introduction – SQL Server on Linux
SQL Server 2017 has been an amazing release of SQL Server. With an obvious decoupling between Windows and SQL Server, now you can run SQL Server on Linux, Docker containers, and even in macOS! This gives you more freedom regarding the platform on which you want to run SQL Server and that is just great. This article aims to help you getting started with SQL Server on Linux.
Linux Distributions Supported by SQL Server 2017
The Linux distributions supported by SQL Server 2017 are:
- Red Hat Enterprise Linux (RHEL) 7.3 or later
- SUSE Linux Enterprise Server (SLES) v.12 with SP2 or later
- Ubuntu Linux 16.04 or later
In this article I will mostly talk about Ubuntu since its free to use, but I will also be making some references to RedHat and SuSe Linux as well.
The major difference in the commands regarding the installation, upgrade, uninstallation and management of the SQL Server services across the above three Linux distributions, has to do with the different package managers they use.
Featured Online Course: Get Started with SQL Server on Linux
- Get started with SQL Server 2019 on Linux
- Learn how to install SQL Server on Linux
- Learn how to access SQL Server on Linux using Azure Data Studio
- Many live demos and guides included!
- Lifetime access
Installing SQL Server on Linux
Installing SQL Server on Linux is very easy. Microsoft has available on their website excellent step-by-step documentation on how to perform the installation.
Below, I provide the links to this documentation/quickstarts:
- Install SQL Server and create a database on Red Hat
- Install SQL Server and create a database on SUSE Linux Enterprise Server
- Install SQL Server and create a database on Ubuntu
We can briefly describe the installation experience by listing the Database Engine’s installation wizard steps:
- Select SQL Server Edition (i.e. Developer Edition – Note: Developer Edition can be only used for development and not for Production purposes).
- Review the License Terms
- Set and confirm the SQL Server Server Administrator (SA) password
If all goes well, you will get the message that setup was succesfully completed and that SQL Server service is starting.
This article assumes that you have followed the above quickstart(s) and you have successfully installed SQL Server on your favorite Linux distribution.
Check the SQL Server Service Status After Installation
In Ubuntu Linux, in order to check the SQL Server service status at any time (i.e. right after the installation of SQL Server Database Engine) you can run the below command:
systemctl status mssql-server
systemctl is the utility that controls the systemd system and service manager.
If SQL Server service is running, right after you run the above command, you will get the message that SQL Server is “active (running)”.
Check for Updates
Another important task is to check for any updates for SQL Server. This can be done by comparing your current installation with the latest SQL Server version in the Linux repositories. This involves two steps:
Update the repository to its latest status by running the command (in Ubuntu):
sudo apt-get update
The above will update your repository status.
Please read the documentation for performing the above for the other two Linux distributions.
Upgrade SQL Server
For Ubuntu Linux: sudo apt-get install mssql-server For RedHat Linux (RHEL): sudo yum update mssql-server For SuSe Linux: sudo zypper update mssql-server
The above will upgrade SQL Server, if necessary, or it will just report that you have the latest version installed.
Uninstalling SQL Server on Linux
If for any case, you need to uninstall your SQL Server installation on Linux, you can do so by running the below commands.
Critical Note: Always take care of your data in order not to lose it. For example, prior to uninstalling SQL Server, you need to backup your databases in a safe location.
Tip: You can find the location of your database files at: /var/opt/mssql/
Below you can find the uninstall commands:
For Ubuntu Linux: sudo apt-get remove mssql-server For RedHat Linux (RHEL): sudo yum remove mssql-server For SuSe Linux: sudo zypper remove mssql-server
Managing SQL Server on Linux
It is very easy to mange the SQL Server service on Linux. As already mentioned above, you can do this with the systemctl utility.
Below you can find the commands for checking the status, stopping and starting SQL Server Database Engine service:
Check status: sudo systemctl status mssql-server Stop SQL Server: sudo systemctl stop mssql-server Start SQL Server: sudo systemctl start mssql-server
Additional SQL Server Services on Linux
Besides the SQL Server database Engine, SQL Server 2017 provides additional services that can be installed on Linux. These services are:
SQL Server Agent
To install (and right after to restart SQL Server):
For Ubuntu Linux: sudo apt-get install mssql-server-agent sudo systemctl restart mssql-server For RedHat Linux (RHEL): sudo yum install mssql-server-agent sudo systemctl restart mssql-server For SuSe Linux: sudo zypper install mssql-server-agent sudo systemctl restart mssql-server
Read more about SQL Server Agent on Linux.
For Ubuntu Linux: sudo apt-get update sudo apt-get install -y mssql-server-fts For RedHat Linux (RHEL): sudo yum install -y mssql-server-fts For SuSe Linux: sudo zypper install mssql-server-fts
Read more about Full-Text Search on Linux.
Integration Services (SSIS)
To install, follow the instruction on this MS Docs article.
SQL Server Client Tools on Linux
At the time of writing this article, you can install two command-line SQL Server client tools on Linux. These are:
- sqlcmd: This is a command-line query utility.
- bcp: This is a utility for Bulk import-export.
Both tools are well-known and easy to use, since they exist for Windows many years now.
To install these tools, you can follow the instructions on this MS Docs article.
Connecting to SQL Server on Linux from Windows
You might be wondering: “Is that possible?“. Of course it is! This is after all the real concept of portability.
So, to connect to your SQL Server instance on Linux, you will need what else rather than SQL Server Management Studio (SSMS)!
Note that you will need SSMS v.17 or later for being able to connect to your SQL Server instance on Linux.
Besides SSMS, you will need two simple details:
- The IP of the Linux machine (note that in Linux you can only have one SQL Server instance)
- The SA user’s password you set during the installation of SQL Server on Linux
Right after you make sure you have the above information, just enter the IP in the “Server Name” text box and after selecting “SQL Server Authentication” in the authentication type, enter the SA user’s credentials and click “Connect”. That’s it! You have just connected to your SQL Server instance on Linux via SSMS on Windows!
Did you find this article useful and interesting? Feel free to leave your comment!
Subscribe to our newsletter and stay up to date with our latest articles on SQL Server and related technologies!
Check out our latest software releases! All our software tools have Community Editions which are free to download.
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© 2018 SQLNetHub
Artemakis Artemiou is a Senior SQL Server Architect, Author, and a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA).