20th December 2024

Installing SQL Server on Ubuntu

Linux support came with SQL Server 2017 release. Now you can run a database server like SQL Server without our SQL Server database open source and without an operating system license. In this article, we will install SQL Server on an Ubuntu machine. For this, we first import the GPG keys with the following command.

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)”

GPG keys
GPG keys

 

We are registering at “Microsoft SQL Server Ubuntu repository for SQL Server 2019”.

Microsoft SQL Server Ubuntu repository
Microsoft SQL Server Ubuntu repository

 

Installing SQL Server

We perform the SQL Server installation with the following commands. At first, we update ubuntu with the “apt-get update” command. Then we do the SQL server setup.

sudo apt-get update
sudo apt-get install -y mssql-server
Installing SQL Server
Installing SQL Server

 

The SQL Server installation download process has been completed. Now we are configuring it. We run the following command to configure SQL Server. On the screen that comes up, we choose which version to install. Here we choose the developer edition.

sudo /opt/mssql/bin/mssql-conf setup
Configure SQL Server
Configure SQL Server

 

We say “Yes” to the next screen and enter the password for “SA“.

 password for "SA"
password for “SA”

 

Configuration and installation did.

Configuration and installation
Configuration and installation

 

We run the following command to see if SQL Server is running. As you can see, SQL Server is running.

systemctl status mssql-server --no-pager
SQL Server is running
SQL Server is running

 

Install SQL command-line tools

From now on, we can connect from the management studio installed on any Windows machine, but we will install SQL command-line tools to connect from Linux.  We run the command. As you can see we got an error. It asks to install “snap“.

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

mssql-tools
mssql-tools

 

LEARN MORE  "TIE Server storage or database are reaching minimum recommended operation conditions thresholds." Mcafee Tie Server Warning and Solition

After installing the “snap“, we install the packages.

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

install "mssql-tools"
install “mssql-tools”

 

After installing the packages, we install Mssql-tools. You can use the following command to install it.

sudo apt-get update
sudo apt-get install mssql-tools.
install mssql-tools
install mssql-tools
install mssql-tools
install mssql-tools
configuring msodbcsql
configuring msqdbcsql
configuring mssql-tools
Configuring mssql-tools

 

We add the path where the SQLcmd command runs to the environment variables.

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

 

Now we can connect to the database server. The command we will use for this is sqlcmd. With the command below, we connected to SQL and pulled the server version.

sqlcmd
sqlcmd

 

Now we are adding some records to the database. As you can see, we created a database called TestDB. We opened a table named “Names” and added two people named Ömer and Mehmet into it.

adding some records to the database
adding some records to the database

 

Now we are pulling data from the database using the “select” command.

select from "dbname"
select from “dbname”

 

Now we are trying to connect from the management studio. For this, we need to learn the IP of our server. “ip a” command shows us the ip information. As you can see, the IP of our virtual machine is 192.168.146.128.

ip a
ip a

 

Now we connect from the management studio.

management studio
management studio

 

As a result, we are connected to the Database Server.

Connected to the Database Server
Connected to the Database Server

 

Leave a Reply

Your email address will not be published. Required fields are marked *