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

適用於: yesSQL Server (僅限 Linux)沒有Azure SQL Database沒有Azure SQL 資料倉儲沒有平行資料倉儲 APPLIES TO: yesSQL Server (Linux only) noAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

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

提示

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

如需常見問題的解答,請參閱Linux 常見問題集 > 的 SQL ServerFor 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 2017。SQL Server 2017 is supported on Red Hat Enterprise Linux (RHEL), SUSE Linux Enterprise Server (SLES), and Ubuntu. 它也支援以 Docker 映像,可以在 Linux 或 Docker for 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.47.3 or 7.4 取得 RHEL 7.4Get RHEL 7.4
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

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

注意

測試並如先前所列的散發套件支援在 Linux 上 SQL Server。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 2017 都有適用於 Linux 的系統需求如下:SQL Server 2017 has the following system requirements for Linux:

記憶體Memory 2 GB2 GB
[File System]File System XFS或是EXT4 (其他檔案系統,例如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 只有 x64-相容x64-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.
  • 只找出 /var/opt/mssql上 NFS 掛接的目錄。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 2017 累積更新CU存放庫。The quickstarts use the SQL Server 2017 Cumulative Update CU repository. 但您可以改為設定GDR存放庫或預覽 (vNext) 存放庫。But you can instead configure the GDR repository or the Preview (vNext) repository. 如需有關儲存機制和設定方式的詳細資訊,請參閱在 Linux 上的 SQL server 設定存放庫For more information on repositories and how to configure them, see Configure repositories for SQL Server on Linux.

重要

如果您先前安裝的 CTP 或 SQL Server 2017 RC 版本,您必須移除預覽存放庫,並註冊公開上市 (GA) 其中一個。If you previously installed a CTP or RC version of SQL Server 2017, you must remove the preview repository and register a General Availability (GA) one. 如需詳細資訊,請參閱 < 在 Linux 上的 SQL server 設定存放庫For more information, see Configure repositories for SQL Server on Linux.

安裝 SQL Server 2017Install SQL Server 2017

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

安裝 SQL Server 2019 previewInstall SQL Server 2019 preview

您可以使用相同的快速入門連結上一節中的 Linux 上安裝 SQL Server 2019 預覽。You can install SQL Server 2019 preview on Linux using the same quickstart links in the previous section. 不過,您必須註冊預覽 (vNext) 存放庫,而不是CU存放庫。However, you must register the Preview (vNext) repository instead of the CU repository. 快速入門會提供有關如何執行這項操作的指示。The quickstarts provide instructions on how to do this.

安裝之後,請考慮進行額外的組態變更,以獲得最佳效能。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 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 版本。If you first change your configured repository, it is possible for the update command to upgrade your version of SQL Server. 如果兩個存放庫間可支援的升級路徑,這是只有大小寫。This is only the case 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 2017 版本降級。It is only supported to downgrade to a release within the same major version, such as SQL Server 2017.

檢查已安裝的 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

若要移除mssql server Linux 上的封裝,請使用其中一個基礎平台上的下列命令: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.

下列範例會設定之 SQL Server Developer edition MSSQL_PID環境變數。The following example configures the Developer edition of SQL Server with the MSSQL_PID environment variable. 它也會接受使用者授權合約 (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 套件 (RHEL 和 SLES)rpm -ivh命令,但上表中的命令會自動安裝相依項目如果可從核准的存放庫。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 Server 授權如何For 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 ServerFor answers to frequently asked questions, see the SQL Server on Linux FAQ.