安装必要的工具
sudo yum install -y wget curl
下载并导入 Microsoft GPG 密钥
sudo curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo rpm --import -
注册 SQL Server 2022 存储库
sudo curl -o /etc/yum.repos.d/mssql-server-2022.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2022.repo
更新包列表
sudo yum update -y
安装 SQL Server 2022
sudo yum install -y mssql-server
配置 SQL Server
sudo /opt/mssql/bin/mssql-conf setup
启动 SQL Server 服务
sudo systemctl start mssql-server
sudo systemctl enable mssql-server
安装 SQL Server 命令行工具
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo
sudo yum install -y mssql-tools unixODBC-devel
将 sqlcmd 和 bcp 添加到 PATH 环境变量
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
使用 sqlcmd 连接到 SQL Server
sudo /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd'