Developed by Microsoft, MS SQL is a Relational Database Management System (RDBMS). It stores data in tables, columns, and rows. Widely used in enterprise deployments, MSSQL is a scalable data platform used for mission-critical business and data solutions.
This article shows how to install Microsoft SQL Server 2019 in Ubuntu 20.04. Also, install the MSSQL tools which helps to connect to the database and run SQL queries, etc.
System Requirements
Memory | 2 GB |
File system | XFS or EXT4(other file systems, such as BTRFS, are unsupported |
Disk space | 6 GB |
Processor speed | 2 GHz |
Processor cores | 2 cores |
Processor type | x64-compatible only |
Install SQL Server on Ubuntu
Update/Upgrade your system
Make sure the system has the most recent software package installed. For this update and upgrade your system.
sudo apt update && sudo apt upgrade
Install GPG Public key
Download and install GPG key from microsoft.
sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Add the repository
Add official repository to install MSSQL server.
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
Install MS SQL Server
Install mssql server just entering following command.
sudo apt install mssql-server -y
It takes some time to install and when it is finished run setup using the following command.
sudo /opt/mssql/bin/mssql-conf setup
Choose server edition. I am going to choose the Developer edition as it is free. You can choose as per your requirement. Also, accept the license by typing 'yes'. Finally, set the administrator password as shown below.
It takes a few minutes to complete and when the installation is done service will be started. You can once verify it using,
systemctl status mssql-server
Install mssql-tool on Ubuntu
The mssql-tool package contains sqlcmd (Command-line query) and bcp (Bulk import-export) utilities.
To install the tool, first add the repository, update it, and install mssql-tools.
curl https://packages.microsoft.com/config/ubuntu/19.10/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list sudo apt update sudo apt install mssql-tools -y
Next, accept the license term as shown below.
The above installation will not make an environmental variable for the execution of mssql tools. So, export them using the following line of command.
echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bashrc source ~/.bashrc
Connect to SQL Server
To connect to SQL server use sqlcmd command. It can be on the remote server or on the same SQl server.
sqlcmd -S localhost -U SA -P 'YourPassword'
To check the MS SQL version, execute the following query after your login,
select @@version go
Similarly, to create a database use the following SQL command.
create database testdb go
Update/Upgrade Microsoft SQL server
We have added a repository from Microsoft to install SQL server. So, to update/upgrade the SQL server run the following command:
sudo apt update && sudo apt install mssql-server
Remove Microsoft SQL server
To completely remove SQL server 2019 and its dependency, you can use the following commands.
sudo apt purge mssql-server mssql-tools -y sudo apt autoremove -y
Conclusion
In this tutorial, we learned how to install Microsoft SQL Server on Ubuntu 20.04 and connect to SQL server to run SQL queries. Thank you for reading.