基本环境

  • CentOS Linux 7 (Core) 内存大于2GB
  • Microsoft SQL Server 2019
    其他系统版本可在 https://packages.microsoft.com/config/ 找到。

设置软件源

yum-config-manager \
    --add-repo \
    https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo
yum clean all && yum makecache

安装

yum install -y mssql-server

安装完成后以root身份运行

┌─(/etc/yum.repos.d)──────────────────────────────────(ROOT@vpn2:pts/0)─┐
└─(01:45:38)──> /opt/mssql/bin/mssql-conf setup           ──(Thu,Sep08)─┘
Choose an edition of SQL Server:
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID) - CPU Core utilization restricted to 20 physical/40 hyperthreaded
  7) Enterprise Core (PAID) - CPU Core utilization up to Operating System Maximum
  8) I bought a license through a retail sales channel and have a product key to enter.

Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=2109348&clcid=0x409

Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.

Enter your edition(1-8): 2
# 选择2或者3 均可,均为免费版本。
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=2104294&clcid=0x409

The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409
# 此处设置 管理员账户密码(SA)
Enter the SQL Server system administrator password: 
Confirm the SQL Server system administrator password: 
Configuring SQL Server...

ForceFlush is enabled for this instance. 
ForceFlush feature is enabled for log durability.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

至此初始化完成,可运行:

ps aux | grep mssql | grep -v grep 

或者

systemctl status mssql-server.service 

查看是否安装成功

二进制文件在/opt/mssql,数据文件在 /var/opt/mssql

安装mssql-tools(CLI)

设置软件源

yum-config-manager \
    --add-repo \
    https://packages.microsoft.com/config/rhel/7/prod.repo
yum clean all && yum makecache

安装

yum install mssql-tools -y
# 注意 此处需要同意 微软 许可条款
The license terms for this product can be downloaded from
https://aka.ms/odbc17eula and found in
/usr/share/doc/msodbcsql17/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
yes
  Installing : msodbcsql17-17.10.1.1-1.x86_64                                                                                                                                                                                        2/3 
odbcinst: Driver installed. Usage count increased to 1. 
    Target directory is /etc
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746949 and found in
/usr/share/doc/mssql-tools/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
yes
# 略

环境变量设置

echo "export PATH=$PATH:/opt/mssql/bin:/opt/mssql-tools/bin" >> /etc/profile
. /etc/profile

链接数据库

┌─(~)───────────────────────────────────────(ROOT@vpn2:pts/0)─┐
└─(02:09:34)──> sqlcmd -S 127.0.0.1 -U SA      ───(Thu,Sep08)─┘
Password: 
1> Select Name FROM Master.dbo.SysDatabases orDER BY Name;
2> go
Name                                                   
----------------------------------------------------------------
master                                                                                                                          
model                                                                                                                           
msdb                                                                                                                            
tempdb                                                                                                                          

(4 rows affected)

开启防火墙

firewall-cmd --permanent --zone=public --add-service=mssql && firewall-cmd --reload