How to Set Up SQL Server on Linux in PostgreSQL

Galaxy Glossary

How do I install and configure Microsoft SQL Server on Linux?

Install, configure, and secure Microsoft SQL Server on a Linux host so you can start creating and querying databases right away.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

What are the hardware and OS prerequisites?

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.

How do I add the Microsoft package repository?

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.

Which command installs the engine?

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).

How do I run the setup wizard non-interactively?

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.

How can I verify the service is healthy?

Check status with systemctl status mssql-server. A healthy instance reports active (running). Use sudo journalctl -u mssql-server for detailed logs.

What’s the quickest way to create an ecommerce database?

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.

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

How do I enable remote TCP connectivity?

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.

What security best practices should I apply?

Create least-privilege logins, enforce strong passwords, back up keys, and keep the host patched with apt/yum update. Always restrict sa usage.

Why How to Set Up SQL Server on Linux in PostgreSQL is important

How to Set Up SQL Server on Linux in PostgreSQL Example Usage


-- List customers with their latest order amount
SELECT c.name,
       o.total_amount AS last_order_total
FROM   Customers c
JOIN   Orders   o ON o.customer_id = c.id
WHERE  o.order_date = (
    SELECT MAX(order_date)
    FROM Orders o2
    WHERE o2.customer_id = c.id
);

How to Set Up SQL Server on Linux in PostgreSQL Syntax


# Ubuntu installation
sudo apt-get update
sudo apt-get install -y mssql-server
sudo /opt/mssql/bin/mssql-conf -n setup \
     accept-eula \
     edition=Developer \
     MSSQL_SA_PASSWORD='StrongP@ssw0rd'

# Connect and create ecommerce objects via sqlcmd
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'StrongP@ssw0rd' <<'SQL'
CREATE DATABASE ecommerce;
GO
USE ecommerce;
GO
CREATE 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
SQL

Common Mistakes

Frequently Asked Questions (FAQs)

Can I run SQL Server in Docker instead of a full install?

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.

How do I automate backups on Linux?

Use sqlcmd inside a cron job that calls BACKUP DATABASE ecommerce TO DISK='/var/backup/ecommerce.bak' WITH COMPRESSION, INIT;.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.