Linux 上的 SQL Server 的安裝指引Installation guidance for SQL Server on Linux

適用於: 是SQL Server (僅限 Linux) 否Azure SQL Database 否Azure Synapse Analytics (SQL DW) 否平行處理資料倉儲 APPLIES TO: yesSQL Server (Linux only) noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

本文提供在 Linux 上安裝、更新及解除安裝 SQL Server 2017 和 SQL Server 2019 的指導方針。This article provides guidance for installing, updating, and uninstalling SQL Server 2017 and SQL Server 2019 on Linux.

如需了解其他部署案例,請參閱:For other deployment scenarios, see:

提示

本指南涵蓋數個部署案例。This guide covers several deployment scenarios. 如果您只是要尋找逐步安裝指示,請跳到其中一個快速入門:If you are only looking for step-by-step installation instructions, jump to one of the quickstarts:

如需常見問題的解答,請參閱 Linux 上的 SQL Server 常見問題集For answers to frequently asked questions, see the SQL Server on Linux FAQ.

支援的平台Supported platforms

Red Hat Enterprise Linux (RHEL)、SUSE Linux Enterprise Server (SLES) 及 Ubuntu 都支援 SQL Server。SQL Server is supported on Red Hat Enterprise Linux (RHEL), SUSE Linux Enterprise Server (SLES), and Ubuntu. 它也支援 Docker 映像,可以在 Linux 上的 Docker 引擎 或適用於 Windows/Mac 的 Docker 上執行。It is also supported as a Docker image, which can run on Docker Engine on Linux or Docker for Windows/Mac.

平台Platform 支援的版本Supported version(s) GetGet
Red Hat Enterprise LinuxRed Hat Enterprise Linux 7.3、7.4、7.5、7.67.3, 7.4, 7.5, 7.6 取得 RHEL 7.6Get RHEL 7.6
SUSE Linux Enterprise ServerSUSE Linux Enterprise Server v12 SP2v12 SP2 取得 SLES v12 SP2Get SLES v12 SP2
UbuntuUbuntu 16.0416.04 取得 Ubuntu 16.04Get Ubuntu 16.04
Docker 引擎Docker Engine 1.8+1.8+ 取得 DockerGet Docker
平台Platform 支援的版本Supported version(s) GetGet
Red Hat Enterprise LinuxRed Hat Enterprise Linux 7.3、7.4、7.5、7.6、8.07.3, 7.4, 7.5, 7.6, 8.0 取得 RHEL 8.0Get RHEL 8.0
SUSE Linux Enterprise ServerSUSE Linux Enterprise Server v12 SP2、SP3、SP4v12 SP2, SP3, SP4 取得 SLES v12Get SLES v12
UbuntuUbuntu 16.0416.04 取得 Ubuntu 16.04Get Ubuntu 16.04
Docker 引擎Docker Engine 1.8+1.8+ 取得 DockerGet Docker

Microsoft 也支援使用 OpenShift 和 Kubernetes 來部署和管理 SQL Server 容器。Microsoft also supports deploying and managing SQL Server containers by using OpenShift and Kubernetes.

注意

SQL Server 已針對先前列出的發行版本,在 Linux 上經過測試並受到支援。SQL Server is tested and supported on Linux for the previously listed distributions. 但如果選擇在不支援的作業系統上安裝 SQL Server,請檢閱 Microsoft SQL Server 的技術支援原則 (機器翻譯) 的<支援原則> 一節以了解隱含的支援。If you choose to install SQL Server on an unsupported operating system, please review the Support policy section of the Technical support policy for Microsoft SQL Server to understand the support implications.

系統需求System requirements

SQL Server 具有下列適用於 Linux 的系統需求:SQL Server has the following system requirements for Linux:

記憶體Memory 2 GB2 GB
檔案系統File System XFSEXT4 (不支援其他檔案系統,例如 BTRFS)XFS or EXT4 (other file systems, such as BTRFS, are unsupported)
磁碟空間Disk space 6 GB6 GB
處理器速度Processor speed 2 GHz2 GHz
處理器核心數Processor cores 2 個核心2 cores
處理器類型Processor type 僅相容 x64x64-compatible only

如果您在生產環境中使用網路檔案系統 (NFS) 遠端共用,請注意下列支援需求:If you use Network File System (NFS) remote shares in production, note the following support requirements:

  • 使用 NFS 版本 4.2 或更新的版本Use NFS version 4.2 or higher. 舊版的 NFS 不支援新式檔案系統常用的必要功能,例如 fallocate 和疏鬆檔案建立。Older versions of NFS do not support required features, such as fallocate and sparse file creation, common to modern file systems.
  • 僅尋找 NFS 掛接上的 /var/opt/mssql 目錄。Locate only the /var/opt/mssql directories on the NFS mount. 不支援其他檔案,例如 SQL Server 系統二進位檔案。Other files, such as the SQL Server system binaries, are not supported.
  • 確定 NFS 用戶端在裝載遠端共用時使用 'nolock' 選項。Ensure that NFS clients use the 'nolock' option when mounting the remote share.

設定來源存放庫Configure source repositories

當您安裝或升級 SQL Server 時,您會從已設定的 Microsoft 存放庫取得最新版本的 SQL Server。When you install or upgrade SQL Server, you get the latest version of SQL Server from your configured Microsoft repository. 快速入門會使用 SQL Server 的累積更新 CU 存放庫。The quickstarts use the Cumulative Update CU repository for SQL Server. 但是,您可以改為設定 GDR 存放庫。But you can instead configure a GDR repository. 如需存放庫和其設定方式的詳細資訊,請參閱針對 Linux 上的 SQL Server 設定存放庫For more information on repositories and how to configure them, see Configure repositories for SQL Server on Linux.

安裝 SQL ServerInstall SQL Server

您可以在 Linux 上從命令列安裝 SQL Server 2017 或 SQL Server 2019。You can install SQL Server 2017 or SQL Server 2019 on Linux from the command line. 如需逐步指示,請參閱下列其中一個快速入門:For step-by-step instructions, see one of the following quickstarts:

平台Platform 安裝快速入門Installation quickstarts
Red Hat Enterprise Linux (RHEL)Red Hat Enterprise Linux (RHEL) 2017 | 20192017 | 2019
SUSE Linux Enterprise Server (SLES)SUSE Linux Enterprise Server (SLES) 2017 | 20192017 | 2019
UbuntuUbuntu 2017 | 20192017 | 2019
DockerDocker 2017 | 20192017 | 2019

您也可以在 Azure 虛擬機器的 Linux 上執行 SQL Server。You can also run SQL Server on Linux in an Azure virtual machine. 如需詳細資訊,請參閱在 Azure 中佈建 SQL VMFor more information, see Provision a SQL VM in Azure.

安裝之後,請考慮進行其他設定變更以獲得最佳效能。After installing, consider making additional configuration changes for optimal performance. 如需詳細資訊,請參閱 Linux 上的 SQL Server 效能最佳做法和設定方針For more information, see Performance best practices and configuration guidelines for SQL Server on Linux.

更新或升級 SQL ServerUpdate or Upgrade SQL Server

若要將 mssql-server 套件更新為最新版本,請根據您的平台,使用下列其中一個命令:To update the mssql-server package to the latest release, use one of the following commands based on your platform:

平台Platform 套件更新命令Package update command(s)
RHELRHEL sudo yum update mssql-server
SLESSLES sudo zypper update mssql-server
UbuntuUbuntu sudo apt-get update
sudo apt-get install mssql-server

這些命令會下載最新的套件,並取代位於 /opt/mssql/ 底下的二進位檔。These commands download the newest package and replace the binaries located under /opt/mssql/. 使用者產生的資料庫和系統資料庫不會受到這項作業的影響。The user generated databases and system databases are not affected by this operation.

若要升級 SQL Server,請先變更您設定的存放庫,將其設為所需的 SQL Server 版本。To upgrade SQL Server, first change your configured repository to the desired version of SQL Server. 然後使用相同的升級命令來升級 SQL Server 版本。Then use the same update command to upgrade your version of SQL Server. 只有在兩個存放庫之間支援升級路徑時,才會發生這種情況。This is only possible if the upgrade path is supported between the two repositories.

復原 SQL ServerRollback SQL Server

若要將 SQL Server 復原或降級至先前的版本,請使用下列步驟:To rollback or downgrade SQL Server to a previous release, use the following steps:

  1. 確認要降級的目標 SQL Server 套件版本號碼。Identify the version number for the SQL Server package you want to downgrade to. 如需套件編號的清單,請參閱版本資訊For a list of package numbers, see the Release notes.

  2. 降級為舊版 SQL Server。Downgrade to a previous version of SQL Server. 在下列命令中,將 <version_number> 取代為您在步驟一中確認的 SQL Server 版本號碼。In the following commands, replace <version_number> with the SQL Server version number you identified in step one.

    平台Platform 套件更新命令Package update command(s)
    RHELRHEL sudo yum downgrade mssql-server-<version_number>.x86_64
    SLESSLES sudo zypper install --oldpackage mssql-server=<version_number>
    UbuntuUbuntu sudo apt-get install mssql-server=<version_number>
    sudo systemctl start mssql-server

注意

其僅支援降級為相同主要版本 (例如 SQL Server 2019) 中的版本。It is only supported to downgrade to a release within the same major version, such as SQL Server 2019.

檢查已安裝的 SQL Server 版本Check installed SQL Server version

若要驗證您 Linux 上的 SQL Server 目前的版本和版次,請使用下列程序:To verify your current version and edition of SQL Server on Linux, use the following procedure:

  1. 如果尚未安裝,請安裝 SQL Server 命令列工具If not already installed, install the SQL Server command-line tools.

  2. 使用 sqlcmd 來執行 Transact-SQL 命令,以顯示您的 SQL Server 版本和版次。Use sqlcmd to run a Transact-SQL command that displays your SQL Server version and edition.

    sqlcmd -S localhost -U SA -Q 'select @@VERSION'
    

解除安裝 SQL ServerUninstall SQL Server

若要移除 Linux 上的 mssql-server 套件,請根據您的平台,請使用下列其中一個命令:To remove the mssql-server package on Linux, use one of the following commands based on your platform:

平台Platform 套件移除命令Package removal command(s)
RHELRHEL sudo yum remove mssql-server
SLESSLES sudo zypper remove mssql-server
UbuntuUbuntu sudo apt-get remove mssql-server

移除套件並不會刪除產生的資料庫檔案。Removing the package does not delete the generated database files. 如果您想要刪除資料庫檔案,請使用下列命令:If you want to delete the database files, use the following command:

sudo rm -rf /var/opt/mssql/

自動安裝Unattended install

您可以透過下列方式執行自動安裝:You can perform an unattended installation in the following way:

  • 遵循快速入門中的初始步驟來註冊存放庫,並安裝 SQL Server。Follow the initial steps in the quickstarts to register the repositories and install SQL Server.
  • 當您執行 mssql-conf setup 時,請設定環境變數,並使用 [-n (無提示)] 選項。When you run mssql-conf setup, set environment variables and use the -n (no prompt) option.

下列範例會使用 MSSQL_PID 環境變數來設定開發人員版本的 SQL Server。The following example configures the Developer edition of SQL Server with the MSSQL_PID environment variable. 它也會接受 EULA (ACCEPT_EULA),並設定 SA 使用者密碼 (MSSQL_SA_PASSWORD)。It also accepts the EULA (ACCEPT_EULA) and sets the SA user password (MSSQL_SA_PASSWORD). -n 參數會執行無訊息安裝,其中會從環境變數提取設定值。The -n parameter performs an unprompted installation where the configuration values are pulled from the environment variables.

sudo MSSQL_PID=Developer ACCEPT_EULA=Y MSSQL_SA_PASSWORD='<YourStrong!Passw0rd>' /opt/mssql/bin/mssql-conf -n setup

您也可以建立指令碼來執行其他動作。You can also create a script that performs other actions. 例如,您可以安裝其他 SQL Server 套件。For example, you could install other SQL Server packages.

如需更詳細的範例指令碼,請參閱下列範例:For a more detailed sample script, see the following examples:

離線安裝Offline install

如果您的 Linux 電腦無法存取快速入門中使用的線上儲存機制,您可以直接下載封裝檔案。If your Linux machine does not have access to the online repositories used in the quick starts, you can download the package files directly. 這些套件位於 Microsoft 存放庫 https://packages.microsoft.com 中。These packages are located in the Microsoft repository, https://packages.microsoft.com.

提示

如果已在快速入門的步驟中順利安裝,則不需要下載或以手動方式安裝 SQL Server 套件。If you successfully installed with the steps in the quick starts, you do not need to download or manually install the SQL Server package(s). 本節只適用於離線情節。This section is only for the offline scenario.

  1. 下載適用於您平台的資料庫引擎套件Download the database engine package for your platform. 版本資訊的 [套件詳細資料] 區段中尋找套件下載連結。Find package download links in the package details section of the Release Notes.

  2. 將已下載套件移至您的 Linux 電腦Move the downloaded package to your Linux machine. 如果您使用不同電腦來下載套件,將套件移至 Linux 電腦的其中一種方式是使用 scp 命令。If you used a different machine to download the packages, one way to move the packages to your Linux machine is with the scp command.

  3. 安裝資料庫引擎套件Install the database engine package. 根據您的平台,使用下列其中一個命令。Use one of the following commands based on your platform. 將此範例中的套件檔案名稱取代為您下載的確切名稱。Replace the package file name in this example with the exact name you downloaded.

    平台Platform 套件安裝命令Package install command
    RHELRHEL sudo yum localinstall mssql-server_versionnumber.x86_64.rpm
    SLESSLES sudo zypper install mssql-server_versionnumber.x86_64.rpm
    UbuntuUbuntu sudo dpkg -i mssql-server_versionnumber_amd64.deb

    注意

    您也可以使用 rpm -ivh 命令來安裝 RPM 套件 (RHEL 和 SLES),但是上表中的命令會自動安裝相依性 (如果可以從已核准的存放庫中取得)。You can also install the RPM packages (RHEL and SLES) with the rpm -ivh command, but the commands in the previous table automatically install dependencies if available from approved repositories.

  4. 解決遺漏的相依性:此時,您可能會遺漏某些相依性。Resolve missing dependencies: You might have missing dependencies at this point. 如果沒有,則您可以略過此步驟。If not, you can skip this step. 在 Ubuntu 上,如果您可以存取包含這些相依性的已核准存放庫,最簡單的解決方案就是使用 apt-get -f install 命令。On Ubuntu, if you have access to approved repositories containing those dependencies, the easiest solution is to use the apt-get -f install command. 此命令也會完成 SQL Server 的安裝。This command also completes the installation of SQL Server. 若要手動檢查相依性,請使用下列命令:To manually inspect dependencies, use the following commands:

    平台Platform 列出相依性命令List dependencies command
    RHELRHEL rpm -qpR mssql-server_versionnumber.x86_64.rpm
    SLESSLES rpm -qpR mssql-server_versionnumber.x86_64.rpm
    UbuntuUbuntu dpkg -I mssql-server_versionnumber_amd64.deb

    解決遺失的相依性之後,再次嘗試安裝 mssql-server 套件。After resolving the missing dependencies, attempt to install the mssql-server package again.

  5. 完成 SQL Server 安裝程式Complete the SQL Server setup. 使用 mssql-conf 來完成 SQL Server 安裝程式:Use mssql-conf to complete the SQL Server setup:

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

授權和定價Licensing and pricing

SQL Server 在 Linux 和 Windows 上都有相同的授權。SQL Server is licensed the same for Linux and Windows. 如需 SQL Server 授權和定價的詳細資訊,請參閱如何授權 SQL ServerFor more information about SQL Server licensing and pricing, see How to license SQL Server.

SQL Server 選用功能Optional SQL Server features

安裝之後,您也可以安裝或啟用選用的 SQL Server 功能。After installation, you can also install or enable optional SQL Server features.

info_tip 取得說明Get help

提示

如需常見問題的解答,請參閱 Linux 上的 SQL Server 常見問題集For answers to frequently asked questions, see the SQL Server on Linux FAQ.