How to Install and Set Up Microsoft SQL Server on Ubuntu
One of the critical parts of most software systems is a database server. A database server is a program used to store and manage data for other software applications.
This guide will show you how to install Microsoft SQL Server on Ubuntu 20.04. SQL Server is one of the robust and widely used database servers in IT. A native SQL Server for Linux has been available since 2017, whereas earlier versions of SQL Server were only available for the Windows operating system.
Installing SQL Server
To get started, import the Microsoft public GNU Privacy Guard (GnuPG) key to your list of trusted keys so that your system establishes an encrypted and secure connection when downloading SQL Server from Microsoft repositories.
Use the command below to import the GnuPG key.
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Now you should register the Microsoft SQL Server Ubuntu package repository for SQL Server 2019. This is the repository from which you will be downloading the SQL Server 2019 for Ubuntu Linux.
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
Note: Replace the version number, i.e. 20.04 in the command above with the LTS version of Ubuntu you are using. For example, if you are using Ubuntu 18.04, replace /ubuntu/20.04 with /ubuntu/18.04.
Update your list of repositories before installing SQL Server so that you get the changes for the newly added repository.
sudo apt update
Finally, install the SQL Server package using the command below.
sudo apt install -y mssql-server
Configuring Your Server
Once the installation is complete, you should proceed to configure your SQL Server instance by setting up the System Administrator (SA) password.
Run the command below to start the configuration of your SQL Server.
sudo /opt/mssql/bin/mssql-conf setup
The first prompt in the configuration will ask you to choose the edition of SQL Server that you want to install. Both paid and free editions are available. This guide will use the SQL Server Express edition, which is option 3. Input your option and press Enter.
The system will then present you with a link to the license terms and a prompt to accept the terms. Enter Yes to agree to the terms, and proceed with the installation.
The next step is to set the System Administrator (SA) password for your SQL Server instance. Use a strong and secure password to avoid your data from being compromised.
You can check the status of your SQL Server service using the systemctl command.
systemctl status mssql-server
Installing Azure Data Studio
There are several ways you can interact with SQL Server databases on Linux, using the command line or via a GUI application; this guide uses the latter.
In this section, you will install Azure Data Studio, a lightweight cross-platform database management tool. You can use Azure Data Studio to query, design, and maintain your database on-premises or in the cloud.
First of all, download the Azure Data Studio Debian package to your Downloads folder.
Download: Azure Data Studio
Install the Azure Data Studio DEB package using the following command.
sudo apt install ~/Downloads/azuredatastudio-linux-1.30.0.deb
Note, the command assumes that the Downloads folder contains the DEB package, so make sure that you are using the correct folder location.
Running Azure Data Studio
Once the installation above is complete, you can start Azure Data Studio from the terminal.
azuredatastudio
The Azure Data Studio welcome screen will look like the one below.
To connect to a database server, click on the New Connection link under the Start section. You will then be prompted to enter your database connection details.
Since the database you are connecting to is located on your PC, use localhost as the server name. The default username is SA. Enter the password that you used when configuring your SQL Server instance. Finally, click the Connect button.
Your Connection Details screen should be similar to the one shown below.
Once connected, the system will list all your databases on the left pane. You can now manage your databases from this screen.
Why Use a SQL-Based Database?
This guide has shown you how to install Microsoft SQL Server, a relational database system, on Ubuntu Linux. In addition, you installed Azure Data Studio to ease the management of your databases. SQL-based databases are easy to manage, very scalable, and widely used by database administrators.
Alternatives to SQL-based databases known as NoSQL databases are now becoming popular, as they use object-oriented schemas for organizing data. Some notable NoSQL databases are Cosmos DB and MongoDB.