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:~$
wget -qO https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(wget -qO https:// packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"
sudo apt-get update
sudo apt-get install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup
systemctl status mssql-server --no-pager
Let’s install Microsoft SQL Server command-line tools.
sudo apt-get update
sudo apt install curl
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
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>
Top comments (0)