How To Install Microsoft SQL Server on Debian 12
In this tutorial, we will show you how to install Microsoft SQL Server on Debian 12. In today’s data-driven world, the need for robust and efficient database management systems is paramount. Microsoft SQL Server stands tall as one of the most popular choices for managing relational databases.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Microsoft SQL Server on a Debian 12 (Bookworm).
Prerequisites
- A server running one of the following operating systems: Debian 12 (Bookworm).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Microsoft SQL Server.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Microsoft SQL Server on Debian 12 Bookworm
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update
This command will refresh the repository, allowing you to install the latest versions of software packages.
Step 2. Installing Microsoft SQL Server on Debian 12.
To access SQL Server, you need to add the official Microsoft repository to your system. Here’s how:
First, import the Microsoft GPG key to ensure that the packages you download are from a trusted source:
sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Next, add the SQL Server repository to your system’s sources.list
file:
sudo curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list
With the repository in place, you’re ready to install Microsoft SQL Server on your Debian 12 system:
sudo apt update sudo apt install mssql-server
During the installation, you’ll be prompted to accept the End-User License Agreement (EULA). Read through the agreement and accept it to proceed.
Start the SQL Server service and enable it to start automatically with your system:
sudo systemctl start mssql-server sudo systemctl enable mssql-server
Step 3. Configuring Firewall Rules.
By default, SQL Server uses port 1433 for communication. You’ll need to add a firewall rule to allow traffic on this port:
sudo ufw allow 1433/tcp
Activate the firewall rule:
sudo ufw reload
To confirm that the firewall rule is active, run:
sudo ufw status
Step 4. Connecting to SQL Server.
With SQL Server installed, configured, and the firewall set up, you’re ready to connect to your SQL Server instance. To interact with SQL Server from the command line, you need the sqlcmd
utility. Install it with the following command:
sudo apt install mssql-tools
Now, let’s connect to SQL Server using sqlcmd
:
sqlcmd -S localhost -U sa -P your_password
Step 5. Backing Up and Restoring Databases.
- Creating a SQL Server Database Backup
sqlcmd -S localhost -U sa -P your_password -Q "BACKUP DATABASE YourDatabase TO DISK='/var/opt/mssql/data/YourDatabase.bak'"
- Restoring a SQL Server Database from Backup
sqlcmd -S localhost -U sa -P your_password -Q "RESTORE DATABASE YourDatabase FROM DISK='/var/opt/mssql/data/YourDatabase.bak'"
Congratulations! You have successfully installed Microsoft SQL. Thanks for using this tutorial to install the latest version of the Microsoft SQL Server on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Microsoft SQL website.