In the following article, I will show you how to install Microsoft SQL Server 2019 on Ubuntu Server 20.04. Microsoft SQL Server is available on various platforms. Not only Windows, now Linux users, as well as Mac users, can install SQL Server on their system. We can also install MS SQL Server on Ubuntu using Docker. But this time, we are not going to use Docker.
Steps to Install Microsoft SQL Server 2019 on Ubuntu Server 20.04
Step 1. Connect to the server and Update Ubuntu
Connect to the Ubuntu Server via SSH or directly to the server. And then, let’s update our system
sudo apt update && sudo apt upgrade
Step 2. Next, add the public key for the SQL Server
Copy and paste this command
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Step 3. Add the Repository
Now we are going to add the Microsoft SQL Server repository.
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
Step 4. Install SQL Server
Now install SQL Server with this command:
sudo apt-get install -y mssql-server
Step 5. Configure SQL Server
Once the installation completes, run the following command to configure the server
sudo /opt/mssql/bin/mssql-conf setup
You will need to choose the SQL Server version, create password for “sa” user and so on.
Next, check the status using this command
sudo systemctl status mssql-server
SQL Server uses port 1433. If you plan to connect remotely, make sure you set the firewall to allow port 1433.
How to Connect to SQL Server
In order to connect to the SQL Server from the localhost, you will need to install mssql-tools. This is the command-line tool to connect and manage SQL Server.
Install SQL Server Command-Line Tool on Ubuntu 20.04
Import the key
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Add repository
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
Install mssql-tools
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
Once installed, we can add the binary file to the PATH environment variable.
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
At this point, we have the SQL command-line tool we need to manage SQL Server.
Connect to SQL Server
Use this command to connect to the SQL Server using sqlcmd.
sqlcmd -S localhost -U sa -P 'YourP@ssword'
If successful, you should get to the command prompt: 1>
Leave a Reply