Install Microsoft SQL Server 2022 preview on Ubuntu 20.04 LTS

Perform the given steps in this tutorial to install Microsoft SQL Server 2022 preview on Ubuntu 20.04 LTS Focal Linux to experience this Database server.

MSSQL Server, unlike MYSQL server, is a proprietary relational database management system developed by Microsoft Corporation. It is based on the standard of current SQL versions and supplements them with a number of other features.

It is intended for enterprise use and is available in several versions and editions. The editions differ in their range of features, hardware requirements, and price. The software is based on the SQL variant Transact-SQL (T-SQL)

Areas of application for Microsoft SQL Server are data warehouse and business intelligence applications. This includes MSSQL Server services such as Reporting Services, Analysis Services, Integration Services, or SQL Server Data Tools (SSDT).

Steps to install MSSQL 2022 on Ubuntu 20.04 Linux

The commands given here can be used on both Desktop and server editions of Ubuntu 20.04. Even on the Linux system based on it such as POP OS, Linux Mint can also use the steps of this tutorial.

1. Add Microsoft public GPG Key

First, add the GPG key that has been used by the developers of the MS SQL server to sign its packages. Our system requires a GPG key to ensure it gets the packages from the added repositories as they were published by its developers.

sudo apt install wget
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

2. Add SQL Server repository Ubuntu

Being a proprietary application, the MSSQL database server is not available to install using the Ubuntu 20.04 LTS system repository. Therefore, we need to add the official repository of it meant for Ubuntu Focal. While performing this tutorial, the latest version of this database was SQL 2019, however, here we are going for the 2022 preview version.

sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-preview.list)"

3. Update your Ubuntu 20.04

After adding the repository, we need to update the package index cache of Ubuntu 20.04, so that our system could recognize the latest packages available through the added repository.

sudo apt update

4. Install Microsoft SQL server 2022 preview on Ubuntu 20.04

We already have the source to get the latest available 2022 preview package for the Microsoft SQL server. Now, we just need to run the given command to install it on Ubuntu 20.04 LTS.

Before installing it, we can check the version of the database server available to install, here is the command:

sudo apt-cache policy mssql-server
check mssql server preview version

Now, to install it use:

sudo apt-get install mssql-server

5. Configure the MSSQL server V 16.0

As you are done with the installation, start configuring your SQL server by running the given command. This will ask you which edition of Microsoft SQL Server you want to install along with a prompt to set the SA (SQL system administrator) password.

sudo /opt/mssql/bin/mssql-conf setup

If you are looking for a free version then either go for Evaluation, Developers, or Express.  Just type the serial number of the edition that you want to install and then hit the Enter key.

Select edition of SQL server to install

Here we have installed the Express, the free one to perform this tutorial. Accept the license and the system will create a service to run automatically with the system boot.

6. Check the status of the service

Well, if you have done all of the above steps, then a system service of Microsoft SQL server will be on your system. To check its status.

sudo systemctl status mssql.service
Check status mssql service

Now, we can connect our database server to manage it graphically using software such as SQL Server Management Studio or Microsoft Azure Data Studio.

7. Install SQL Server command-line tools

If you want to use the MSSQL server using the command line then follow the given steps:

To create a database using the command line we need a tool that can run Transact-SQL statements on the SQL Server. Therefore for that install tools – sqlcmd and bcp.

However, to get the command tools for the MSSQL server we have to add a Microsoft production repository for Linux.

curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Run system update

sudo apt update

Install MSSQL command tools

sudo apt-get install mssql-tools unixodbc-dev

After completing the installation, use the given command to add the tool folder to your system path, so that we can use it from anywhere in the terminal, regardless of the directory in which we currently are.

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
source ~/.bashrc

8. Create a Database

Well, once the MSSQL tools are on your system, we can create an SQL database using the command terminal of Ubuntu. For that first log in to the SQL command shell by using the SA account and password.

sqlcmd -S localhost -U SA -P 'YourPassword'

Note: Replace YourPassword with the actual password you have set while configuring the MSSQL.

Now, create your DB, using the given command:

CREATE DATABASE myfistdb

To execute the above command, use:

GO

For creating table  

Select the DB first:

USE myfistdb

Now, let’s create a table with a name – firstable

CREATE TABLE firstable (id INT, name NVARCHAR(50), quantity INT)

To Insert data into the new table:

INSERT INTO firstable VALUES (1, 'mango', 150); INSERT INTO firstable VALUES (2, 'carrot', 154);

For executing the above commands, again use:

GO

Whereas to exit the SQLCMD command-line shell, use:

QUIT

This was a quick tutorial to install and use Microsoft SQL Server on Ubuntu 20.04 LTS Linux. To know how to use this database further, see the official tutorial provided by Microsoft.

Other Articles:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.