温馨提示×

Debian怎么安装SQL Server

小樊
49
2026-07-01 15:59:00
栏目: 云计算

Debian 上安装 Microsoft SQL Server 是可以的,但需要注意:SQL Server 官方主要支持 Ubuntu / RHEL,Debian 并不是官方一级支持平台
不过,Debian 12 / 11 通常可以借助 Ubuntu 仓库 成功安装。

下面是在 Debian 12(Bookworm)上安装 SQL Server 2022 的实用步骤(推荐做法)。


一、系统要求

  • Debian 12(或 11)
  • 内存 ≥ 2GB(建议 4GB)
  • 磁盘 ≥ 6GB
  • root 或 sudo 权限

二、安装步骤

1️⃣ 安装依赖

sudo apt update
sudo apt install -y curl wget gnupg apt-transport-https

2️⃣ 添加 Microsoft 仓库(使用 Ubuntu 源)

SQL Server 官方没有 Debian 仓库,但 Ubuntu 22.04 的仓库通常可用。

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/microsoft-archive-keyring.gpg

sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 main" > /etc/apt/sources.list.d/mssql-server.list'

3️⃣ 安装 SQL Server

sudo apt update
sudo apt install -y mssql-server

4️⃣ 初始化 SQL Server

运行配置工具:

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

会提示你:

  • 选择版本
    • 1 Evaluation
    • 2 Developer(推荐)
    • 3 Express
  • 设置 SA 密码(必须强密码)

✅ 完成后会自动启动服务。


5️⃣ 检查服务状态

systemctl status mssql-server

如果未启动:

sudo systemctl start mssql-server
sudo systemctl enable mssql-server

三、安装命令行工具(可选但强烈推荐)

安装 sqlcmd / bcp

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/microsoft-prod.gpg

sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/ubuntu/22.04/prod main" > /etc/apt/sources.list.d/msprod.list'

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

添加到 PATH:

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

测试连接:

sqlcmd -S localhost -U SA -P 你的密码

四、防火墙(如有)

sudo ufw allow 1433/tcp

五、常见问题

❓ Debian 官方支持吗?

❌ 不支持
✅ 但 Debian 12 + Ubuntu 22.04 仓库 实测可用

❓ 内存不足会怎样?

SQL Server 会启动失败或自动停止。


六、卸载 SQL Server

sudo apt remove mssql-server
sudo apt purge mssql-server

如果你愿意,我可以:

  • ✅ 给你 Debian 11 专用方案
  • ✅ 配置 远程连接
  • ✅ 安装 SQL Server 2019
  • ✅ 对比 Docker 安装方案(更稳定)

你打算用 SQL Server 做什么?生产还是学习?

0