Microsoft SQL Server 是微软的数据库管理系统, 在 2016 年把它开源, 从 SQL Server 2017 开始, 可以在主流的 Linux 发行版用套件安装。
以下是在 RHEL 8, Rocky Linux 8 或其他 RHEL 8 分支, 安装 MS SQL 2019 的方法。
首先把 Microsoft SQL Server 2019 的 Repository 加入, 那便可以用 dnf / yum 安装:
$ sudo curl https://packages.microsoft.com/config/rhel/8/prod.repo -o /etc/yum.repos.d/msprod.repo
接着便可以用 dnf 安装:
- $ sudo dnf -y install mssql-server
然后画面会显示版权, 输入 “YES” 同意:
Accept License Agreement when you see a prompt:
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)
安装好 MS SQL Server 后, 安装 SQL Server 的 CLI 工具:
- $ sudo yum -y install mssql-tools unixODBC-devel
同样需要同意版权, 输入 “YES”.
安装好所需套件后, 输行 mssql-conf 初始化 MS SQL 数据库引擎:
- $ sudo /opt/mssql/bin/mssql-conf setup
从选项选择使用那个版本:
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)
7) Enterprise Core (PAID)
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=852748&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”, 开始者免费版本。
然后再次需要同意版权及设定管理员密码:
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.
完成设定密码后, 初始化程式会自动启动 MS SQL Server, 并设定开始自动启动。
最后把 /opt/mssql/bin/ 目录加入 $PATH, 那便不用输入完整 mssql 指令的路径:
-
$ echo ‘export PATH=$PATH:/opt/mssql/bin:/opt/mssql-tools/bin’ | sudo tee /etc/profile.d/mssql.sh
$ source /etc/profile.d/mssql.sh
如果需要给远端的机器连接, 需要在 firewalld 开启埠号 1433:
-
$ sudo firewall-cmd –add-port=1433/tcp –permanent
$ sudo firewall-cmd –reload
现在可以测试是否可以连接 SQL Server:
- $ sqlcmd -S localhost -U SA
输入上面设定的密码, 如果成功连接, 那便安装完成了。