23rd October 2021

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.

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.

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.

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.

SQL Server is running
SQL Server is running

 

LEARN MORE  Installing Packet Tracer on Ubuntu

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“.

mssql-tools
mssql-tools

 

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

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

 

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

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.

 

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.

LEARN MORE  What is Ransomware? Ransomware Example with Python - Types of Ransomware
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 *