Thursday, July 4, 2024
HomeOperating SystemsUbuntuHow To Install Microsoft SQL Server 2022 on Ubuntu 20.04

How To Install Microsoft SQL Server 2022 on Ubuntu 20.04

In today’s article we will discuss the installation, configuration and usage of Microsoft SQL Server 2022 on Ubuntu 20.04. Microsoft SQL Server is very powerful and widely used relational database management system (RDBMS) developed by Microsoft. It is used to store and manage data in a structured way for users to easily retrieve and analyze information at their convenience. This database server has support for various types of data, including unstructured, structured, semi-structured data. It is an ideal choice for data warehousing and business intelligence applications.

Before performing an installation of SQL Server 2022 on an Ubuntu system, you should know it is available in several editions, including the Developer, Standard, Enterprise, Web, and Express editions. Each edition has different levels of pricing and functionality. By adopting SQL Server you will enjoy seamless integration with other Microsoft products, such as SharePoint, Microsoft Excel, and Power BI, making it a popular choice for businesses that use Microsoft technology.

 Install Microsoft SQL Server 2022 on Ubuntu 20.04

Follow our steps shared in this section to install Microsoft SQL Server 2022 on Ubuntu 20.04. This can be done on server or desktop version of Ubuntu operating system.

Step 1: Update Ubuntu system

Run the following commands to update package index on Ubuntu system.

sudo apt update

We also recommend performing an upgrade of all installed applications.

sudo apt upgrade -y

If an system reboot is required after the upgrade, perform the action.

[ -f /var/run/reboot-required ] && sudo reboot -f

Step 2: Add Microsoft APT repository

Once the system is updated, install basic repository configuration packages.

sudo apt install wget curl libssl-dev gpg gnupg2 software-properties-common apt-transport-https lsb-release ca-certificates

Then import the public repository GPG keys:

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/

Next we register Microsoft SQL Server Ubuntu repository:

wget https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list
sudo mv mssql-server-2022.list /etc/apt/sources.list.d/microsoft-prod.list

Step 3: Install Microsoft SQL Server

Install Microsoft SQL Server 2022 on Ubuntu by using below commands:

sudo apt update
sudo apt install mssql-server

Proceed with the installation as prompted.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  gdb libatomic1 libbabeltrace1 libboost-regex1.74.0 libc++1 libc++1-14 libc++abi1-14 libc6-dbg libdebuginfod-common libdebuginfod1 libipt2 libsasl2-modules-gssapi-mit libsource-highlight-common
  libsource-highlight4v5 libsss-nss-idmap0 libunwind-14
Suggested packages:
  gdb-doc gdbserver clang
The following NEW packages will be installed:
  gdb libatomic1 libbabeltrace1 libboost-regex1.74.0 libc++1 libc++1-14 libc++abi1-14 libc6-dbg libdebuginfod-common libdebuginfod1 libipt2 libsasl2-modules-gssapi-mit libsource-highlight-common
  libsource-highlight4v5 libsss-nss-idmap0 libunwind-14 mssql-server
0 upgraded, 17 newly installed, 0 to remove and 4 not upgraded.
Need to get 288 MB of archives.
After this operation, 1,324 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Below is the output you’ll expect from successful installation

.....

Creating config file /etc/profile.d/debuginfod.sh with new version

Creating config file /etc/profile.d/debuginfod.csh with new version
Setting up libdebuginfod1:amd64 (0.186-1build1) ...
Setting up libsource-highlight-common (3.1.9-4.1build2) ...
Setting up libc6-dbg:amd64 (2.35-0ubuntu3.1) ...
Setting up libunwind-14:amd64 (1:14.0.0-1ubuntu1) ...
Setting up libc++abi1-14:amd64 (1:14.0.0-1ubuntu1) ...
Setting up libboost-regex1.74.0:amd64 (1.74.0-14ubuntu3) ...
Setting up libatomic1:amd64 (12.1.0-2ubuntu1~20.04) ...
Setting up libipt2 (2.0.5-1) ...
Setting up libbabeltrace1:amd64 (1.5.8-2build1) ...
Setting up libsss-nss-idmap0 (2.6.3-1ubuntu3.2) ...
Setting up libsasl2-modules-gssapi-mit:amd64 (2.1.27+dfsg2-3ubuntu1.1) ...
Setting up libsource-highlight4v5 (3.1.9-4.1build2) ...
Setting up libc++1-14:amd64 (1:14.0.0-1ubuntu1) ...
Setting up gdb (12.1-0ubuntu1~20.04) ...
Setting up libc++1:amd64 (1:14.0-55~exp2) ...
Setting up mssql-server (16.0.4003.1-1) ...

+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+

Step 4: Configure SQL Server system

Before we can use SQL server we need to initialize it. This will set admin user password and generate necessary configurations.

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

Choose an edition of SQL Server:

 1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID) - CPU core utilization restricted to 20 physical/40 hyperthreaded
  7) Enterprise Core (PAID) - CPU core utilization up to Operating System Maximum
  8) I bought a license through a retail sales channel and have a product key to enter.
  9) Standard (Billed through Azure) - Use pay-as-you-go billing through Azure.
 10) Enterprise Core (Billed through Azure) - Use pay-as-you-go billing through Azure.

Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=2109348&clcid=0x409

Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.
By choosing an edition billed Pay-As-You-Go through Azure, you are verifying
that the server and SQL Server will be connected to Azure by installing the
management agent and Azure extension for SQL Server.

Enter your edition(1-10): 2

Accept license terms:

The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=2104294&clcid=0x409

The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409

Do you accept the license terms? [Yes/No]:Yes

The configuration of SQL Server should complete in few seconds and ready for use.

Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
Configuring SQL Server...

ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

The MS SQL service is automatically started for you. To check its status run the following commands.

$ systemctl status mssql-server.service
 mssql-server.service - Microsoft SQL Server Database Engine
     Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-02-22 18:53:30 UTC; 6min ago
       Docs: https://docs.microsoft.com/en-us/sql/linux
   Main PID: 2508 (sqlservr)
      Tasks: 149
     Memory: 935.1M
     CGroup: /system.slice/mssql-server.service
             ├─2508 /opt/mssql/bin/sqlservr
             └─2553 /opt/mssql/bin/sqlservr

Feb 22 18:53:41 focal sqlservr[2553]: [101B blob data]
Feb 22 18:53:41 focal sqlservr[2553]: [145B blob data]
Feb 22 18:53:41 focal sqlservr[2553]: [75B blob data]
Feb 22 18:53:41 focal sqlservr[2553]: [96B blob data]
Feb 22 18:53:41 focal sqlservr[2553]: [100B blob data]
Feb 22 18:53:41 focal sqlservr[2553]: [71B blob data]
Feb 22 18:53:41 focal sqlservr[2553]: [124B blob data]
Feb 22 18:58:39 focal sqlservr[2553]: [75B blob data]
Feb 22 18:58:59 focal sqlservr[2553]: [156B blob data]
Feb 22 18:58:59 focal sqlservr[2553]: [195B blob data]

Step 5: Install the SQL Server command-line tools

You’ll need to have SQL Server command-line tools installed before you can connect to DB server and run Transact-SQL statements on SQL Server. The following steps install the SQL Server command-line tools: sqlcmd and bcp.

Start by importing the public repository GPG keys.

curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc

Next we add the repository to our system.

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

Install MS SQL server command line tools.

sudo apt update
sudo apt install mssql-tools unixodbc-dev

Also add /opt/mssql-tools/bin/ to your PATH environment variable for ease of access to command-line tools.

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

Step 6: Connect to MS SQL Server database server

To connect to the database server from command line use sqlcmd command. Parameters to be used are:

  • -S : Specify SQL Server name
  • -U : Set username
  • -P : Providing user password

In our example we’re connecting locally, so the server name is localhost. The user name is sa and the password is the one you provided for the SA account during setup.

sqlcmd -S localhost -U sa -P '<YourPassword>'

If you omit the password on the command line you’ll be prompted to enter it. If the connection is successful you’ll get to a sqlcmd command prompt: 1>.

1> CREATE DATABASE TestDB;
3> SELECT Name from sys.databases;
5> GO
Name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
TestDB

(5 rows affected)
1> QUIT

For remote connection specify your database server’s IP address for the -S parameter, and make sure port 1433 is open on your firewall. We hope this article on installation and configuration of MS SQL server 2022 on Ubuntu 20.04 was easy to follow and worked for you. If you have any query or feedback, please share through our comments section.

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

Most Popular

Recent Comments