Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kstevenson722/3fff3a76b3f25d4693a2da53438f3341 to your computer and use it in GitHub Desktop.
Save kstevenson722/3fff3a76b3f25d4693a2da53438f3341 to your computer and use it in GitHub Desktop.

Setup Microsoft SQL Server on Ubuntu 20.04

✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨
YouTube Setup Microsoft SQL Server on Ubuntu 20.04 🔗 https://youtu.be/x6pYoWwtVAY
✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨
SUPPORT MY WORK - Everything Helps Thanks YouTube 🔗 https://YouTube.GetMeTheGeek.com
Buy Me a Coffee ☕ https://www.buymeacoffee.com/getmethegeek
Hire US 🔗 https://getmethegeek.com
✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨

Update Ubuntu

sudo apt update
sudo apt upgrade -y
sudo reboot

Import Microsoft public repository GPG key for Ubuntu

sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Register the Microsoft SQL Server Ubuntu repository for SQL Server 2019

sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"

Install SQL Server

sudo apt update
sudo apt install -y mssql-server

Configure SQL server and set SA password

sudo /opt/mssql/bin/mssql-conf setup

Check SQL service is running

systemctl status mssql-server --no-pager

Check the listening port for MSSQL server

sudo apt install net-tools
sudo netstat -tnlp | grep sqlservr

Open up the firewall port 1433 to connect remotely

Allow ssh and enable firewall

sudo ufw allow 22
sudo ufw allow 1433
sudo ufw allow 1434
sudo ufw enable

Install SQL Server command-line tools

Import the public repository GPG keys.

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

Register the Microsoft Ubuntu repository

curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Install tools and ODBC drivers

sudo apt update 
sudo apt install -y mssql-tools unixodbc-dev

Add tools folder to PATH environment variable in a bash shell.

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

Connect to your server

sqlcmd -S localhost -U SA -P 'Password'

If successful, you should get a command prompt: 1>.

Attaching existing SQL Server Database

Copy yourdbname.mdf and yourdbname_log.ldf to the /var/opt/mssql/data/ directory. Set the owner and permissions to mssql.

sudo cp yourdbname* /var/opt/mssql/data/
sudo su
Chown mssql:mssql /var/opt/mssql/data/yourdbname*
chmod u=+rw,g=+rw,o=-rw  /var/opt/mssql/data/yourdbname*

Run sql on the master

USE master;

CREATE DATABASE yourdbname 
ON PRIMARY (FILENAME = '/var/opt/mssql/data/yourdbname.mdf'),
   (FILENAME = '/var/opt/mssql/data/yourdbname_log.ldf') 
FOR ATTACH
@nKeee
Copy link

nKeee commented Nov 23, 2022

Hello, I get this error

The following packages have unmet dependencies:
mssql-server : Depends: libldap-2.4-2 but it is not installable

I tried to install this library but I couldn't install it. Can anyone solve this? I use Ubuntu. Thanks.

You're probably not running the right Ubuntu version.

@abu3baid
Copy link

great guide!
thank you so much.

@ChrisG-HGH
Copy link

Hello, I get this error

The following packages have unmet dependencies:
mssql-server : Depends: libldap-2.4-2 but it is not installable

I tried to install this library but I couldn't install it. Can anyone solve this? I use Ubuntu. Thanks.

You're probably not running the right Ubuntu version.

I am getting the exact same error. I have done a clean install of Ubuntu Server 20.04 LTS, as the docs say this is the highest supported version of Ubuntu for SQL Server. My guess is that when Ubuntu Server 20.04 LTS is installed, it does some degree of self-updates, and that breaks libldap-2.4-2...

I hope someone else who has also seen this error in 20.04 LTS knows how to work around it!

@ChrisG-HGH
Copy link

Just to answer my own question, I solved it by downloading the libldap-2.4-2 from Debian

wget http://ftp.us.debian.org/debian/pool/main/o/openldap/libldap-2.4-2_2.4.47+dfsg-3+deb10u7_amd64.deb
sudo dpkg -i libldap-2.4-2_2.4.47+dfsg-3+deb10u7_amd64.deb

@SamukaDEV
Copy link

Just to answer my own question, I solved it by downloading the libldap-2.4-2 from Debian

wget http://ftp.us.debian.org/debian/pool/main/o/openldap/libldap-2.4-2_2.4.47+dfsg-3+deb10u7_amd64.deb sudo dpkg -i libldap-2.4-2_2.4.47+dfsg-3+deb10u7_amd64.deb

I have faced the same problem, and solved with this comment, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment