Getting Started with SQL Server on Linux

In this article, we will be discussing about, how you can easily get started with SQL Server on Linux, mainly in terms of installing and managing different SQL Server services on Linux.

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.

 

Getting Started with SQL Server on Linux - Article on SQLNetHub

 

Linux Distributions Supported by SQL Server 2017

The Linux distributions supported by SQL Server 2017 are:

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.

 


Strengthen your SQL Server Administration Skills – Enroll to our Online Course!

Check our online course on Udemy titled “Essential SQL Server Administration Tips
(special limited-time discount included in link).

Via the course, you will learn essential hands-on SQL Server Administration tips on SQL Server maintenance, security, performance, integration, error handling and more. Many live demonstrations and downloadable resources included!

Essential SQL Server Administration Tips - Online Course with Live Demonstrations and Hands-on Guides
(Lifetime Access/ Live Demos / Downloadable Resources and more!)

Learn More


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:

We can briefly describe the installation experience by listing the Database Engine’s installation wizard steps:

  1. Select SQL Server Edition (i.e. Developer Edition – Note: Developer Edition can be only used for development and not for Production purposes).
  2. Review the License Terms
  3. 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:

  1. 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.

  2. 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.

 

Getting Started with SQL Server on Linux - Article on SQLNetHub

 

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.

  • Full-Text Search

    To install:

    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.

 

Featured Online Courses:

 

Read Also

 

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)

Loading...

Reference: SQLNetHub.com (https://www.sqlnethub.com)

© SQLNetHub