Linux 上的 SQL Server 的安装指南Installation guidance for SQL Server on Linux

适用对象:是SQL Server(仅限 Linux)否Azure SQL 数据库 否Azure SQL 数据仓库 否并行数据仓库 APPLIES TO: yesSQL Server (Linux only) noAzure SQL Database noAzure SQL Data Warehouse 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 preview on Linux.

提示

本指南涵盖了多种部署方案。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 Server 常见问题解答For answers to frequently asked questions, see the SQL Server on Linux FAQ.

支持的平台Supported platforms

SQL Server 2017 在 Red Hat Enterprise Linux (RHEL)、SUSE Linux Enterprise Server (SLES) 和 Ubuntu 上受支持。SQL Server 2017 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) 获取Get
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

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 2017 对 Linux 具有以下系统要求:SQL Server 2017 has the following system requirements for Linux:

内存Memory 2 GB2 GB
“文件系统”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 仅兼容 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 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.

安装 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:

安装后,请考虑进行其他配置更改以实现最佳性能。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 Server 2019 预览版Install 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.

更新 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.

提示

如果首先更改已配置的存储库,则可以使用“update”命令升级 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> 替换为步骤 1 中标识的 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”运行显示 SQL Server 版本的 Transact-SQL 命令 。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.comThese 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. 如果使用了不同的计算机下载包,则可以通过“scp”命令将包移至你的 Linux 计算机 。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

对于 Linux 和 Windows,SQL Server 获得的许可都相同。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 Server 常见问题解答For answers to frequently asked questions, see the SQL Server on Linux FAQ.