Install, configure, and secure Microsoft SQL Server on a Linux host so you can start creating and querying databases right away.
64-bit Ubuntu 20.04/22.04, RHEL 8/9, or SLES 15 with ≥2 GB RAM and ≥6 GB free disk are required. Open TCP 1433 in the firewall before installation.
Ubuntu: wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
then sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list)"
. RHEL & SLES use sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/9/mssql-server-2022.repo
.
Update the package cache and install: sudo apt-get update && sudo apt-get install -y mssql-server
(Deb-based) or sudo yum install -y mssql-server
(RPM-based).
Use the configuration script once: sudo /opt/mssql/bin/mssql-conf -n setup accept-eula edition=Developer MSSQL_SA_PASSWORD='StrongP@ssw0rd'
. This sets edition, accepts the EULA, and defines the sa
password.
Check status with systemctl status mssql-server
. A healthy instance reports active (running). Use sudo journalctl -u mssql-server
for detailed logs.
Install the tools, connect, and run a batch file: sudo apt-get install -y mssql-tools unixodbc-dev
then sqlcmd -S localhost -U sa -P 'StrongP@ssw0rd' -i ~/ecommerce.sql
.
CREATE DATABASE ecommerce;GOUSE ecommerce;GOCREATE TABLE Customers(id INT PRIMARY KEY, name NVARCHAR(100), email NVARCHAR(100), created_at DATETIME2);CREATE TABLE Orders(id INT PRIMARY KEY, customer_id INT, order_date DATETIME2, total_amount DECIMAL(10,2));CREATE TABLE Products(id INT PRIMARY KEY, name NVARCHAR(100), price DECIMAL(10,2), stock INT);CREATE TABLE OrderItems(id INT PRIMARY KEY, order_id INT, product_id INT, quantity INT);GO
Edit /opt/mssql/mssql.conf
and set [network] tcpport = 1433
, restart with sudo systemctl restart mssql-server
, and open the port in ufw
or firewalld
.
Create least-privilege logins, enforce strong passwords, back up keys, and keep the host patched with apt/yum update
. Always restrict sa
usage.
Yes. Pull the image with docker pull mcr.microsoft.com/mssql/server:2022-latest
and run docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=StrongP@ssw0rd' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
.
Use sqlcmd
inside a cron job that calls BACKUP DATABASE ecommerce TO DISK='/var/backup/ecommerce.bak' WITH COMPRESSION, INIT;
.