DEV Community

Dmitry Romanoff
Dmitry Romanoff

Posted on

How to install MSSQL Server on Ubuntu?

In this blog I will demonstrate how to install Microsoft SQL Server on Ubuntu.

dmi@dmi-VirtualBox:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
dmi@dmi-VirtualBox:~$
Enter fullscreen mode Exit fullscreen mode
wget -qO https://packages.microsoft.com/keys/microsoft.asc | sudo  apt-key add -
Enter fullscreen mode Exit fullscreen mode
sudo add-apt-repository "$(wget -qO https:// packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
Enter fullscreen mode Exit fullscreen mode

How to install MSSQL Server on Ubuntu

sudo apt-get update
sudo apt-get install -y mssql-server
Enter fullscreen mode Exit fullscreen mode

How to install MSSQL Server on Ubuntu

sudo /opt/mssql/bin/mssql-conf setup
Enter fullscreen mode Exit fullscreen mode

How to install MSSQL Server on Ubuntu

How to install MSSQL Server on Ubuntu

systemctl status mssql-server --no-pager
Enter fullscreen mode Exit fullscreen mode

How to install MSSQL Server on Ubuntu

Let’s install Microsoft SQL Server command-line tools.

sudo apt-get update
sudo apt install curl
Enter fullscreen mode Exit fullscreen mode
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Enter fullscreen mode Exit fullscreen mode
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
Enter fullscreen mode Exit fullscreen mode
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
Enter fullscreen mode Exit fullscreen mode
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Relogin

Connect to the Microsoft SQL Server locally:

dmi@dmi-VirtualBox:~$ sqlcmd -S localhost -U SA
Password:
1> select @@version
2> go
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------
Microsoft SQL Server 2019 (RTM-CU15) (KB5008996) -
15.0.4198.2 (X64)
Jan 12 2022 22:30:08
Copyright (C) 2019 Microsoft Corporation
Enterprise Evaluation Edition (64-bit) on
Linux (Ubuntu 20.04.4 LTS) <X64>
(1 rows affected)
1>
Connect to the MS SQL Server remotely:
dmi@dmi-VirtualBox:~$ sqlcmd -S 192.168.0.77 -U SA
Password:
1>
Let’s create some DB and some table:
dmi@dmi-VirtualBox:~$ sqlcmd -S 192.168.0.77 -U SA
Password:
1> create database mydb
2> go
1>
2> select name from sys.databases
3> go
name
------------------------------------------------------
------------------------------------------------------
--------------------
master
tempdb
model
msdb
mydb
(5 rows affected)
1> use mydb
2> go
Changed database context to 'mydb'.
2> create table my_table(id int, name nvarchar(100))
3> go
1>
2>
3> insert into my_table values(1, 'One')
4> go
(1 rows affected)
1> select * from my_table
2> go
id name
-----------
------------------------------------------------------
----------------------------------------------
1 One
(1 rows affected)
1>
Enter fullscreen mode Exit fullscreen mode

How to install MSSQL Server on Ubuntu

Top comments (0)