Skip to content

Instantly share code, notes, and snippets.

@alphaolomi
Last active May 31, 2023 06:59
Show Gist options
  • Save alphaolomi/8cac6917398a684aec2d271a0b5d6391 to your computer and use it in GitHub Desktop.
Save alphaolomi/8cac6917398a684aec2d271a0b5d6391 to your computer and use it in GitHub Desktop.
SQL Server for Linux(Debian/Ubuntu)

SQL Server

Install the SQL Server command-line tools

  • Import the public repository GPG keys.
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  • Register the Microsoft repository.
wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list | sudo tee /etc/apt/sources.list.d/msprod.list
  • Update the sources list and run the installation command with the unixODBC developer package.

For more information, see

sudo apt-get update
sudo apt-get install mssql-server
sudo apt-get install mssql-tools unixodbc-dev

-After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup
  • Optional: Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.

To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile or ~/.zshrc file with the following command:

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# if your using ZSH Shell use this
# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.zshrc
source ~/.zshrc
  • Confirm SQL Server is running
systemctl status mssql-server --no-pager
# Service should be active

Using the database locally

Connect locally

  • Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost. The user name is SA and the password is the one you provided for the SA account during setup.
  • SA stand for System Administrator

You can omit the password on the command line to be prompted to enter it.

sqlcmd -S localhost -U SA -P '<YourPassword>'

See SQL_Server_cheat_sheet

@ananthpillai
Copy link

ananthpillai commented Nov 2, 2022

Thank you so much for writing these steps, detailing on "how to install the SQL Server command line tools" on Debian.

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