RHEL 8 / Rocky Linux 8 安裝 MS SQL Server 2019


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/mssql-server-2019.repo -o /etc/yum.repos.d/mssql-server-2019.repo
$ sudo curl https://packages.microsoft.com/config/rhel/8/prod.repo -o /etc/yum.repos.d/msprod.repo

接著便可以用 dnf 安裝:

/linux/

  • $ 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 工具:

/linux/

  • $ sudo yum -y install mssql-tools unixODBC-devel

同樣需要同意版權, 輸入 “YES”.

安裝好所需套件後, 輸行 mssql-conf 初始化 MS SQL 資料庫引擎:

/linux/

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

從選項選擇使用那個版本:

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)
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”, 開始者免費版本。

然後再次需要同意版權及設定管理員密碼:

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 /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 指令的路徑:

/linux/

  • $ 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:

/linux/

  • $ sudo firewall-cmd –add-port=1433/tcp –permanent
    $ sudo firewall-cmd –reload

現在可以測試是否可以連接 SQL Server:

/linux/

  • $ sqlcmd -S localhost -U SA

輸入上面設定的密碼, 如果成功連接, 那便安裝完成了。

Leave a Reply