在 Linux 上使用环境变量配置 SQL Server 设置Configure SQL Server settings with environment variables on Linux

11/04/2019

本文内容

适用于:Applies to:

SQL SERVER 什么算生产环境 sql server环境变量配置_TCP

SQL ServerSQL Server(所有支持的版本)

SQL SERVER 什么算生产环境 sql server环境变量配置_TCP

SQL ServerSQL Server (all supported versions) - Linux适用于:Applies to:

SQL SERVER 什么算生产环境 sql server环境变量配置_TCP

SQL ServerSQL Server(所有支持的版本)

SQL SERVER 什么算生产环境 sql server环境变量配置_TCP

SQL ServerSQL Server (all supported versions) - Linux

可在 Linux 上使用多种不同的环境变量配置 SQL Server 2017。You can use several different environment variables to configure SQL Server 2017 on Linux. 这些变量用于两个方案:These variables are used in two scenarios:

可在 Linux 上使用多种不同的环境变量配置 SQL Server 2019。You can use several different environment variables to configure SQL Server 2019 on Linux. 这些变量用于两个方案:These variables are used in two scenarios:

使用 mssql-conf setup 命令配置初始设置。To configure initial setup with the mssql-conf setup command.

提示

If you need to configure SQL Server after these setup scenarios, see Configure SQL Server on Linux with the mssql-conf tool.

环境变量Environment variables

环境变量Environment variable

说明Description

ACCEPT_EULAACCEPT_EULA

将 ACCEPT_EULA 变量设置为任意值,以确认接受 最终用户许可协议。Set the ACCEPT_EULA variable to any value to confirm your acceptance of the End-User Licensing Agreement. SQL Server 映像的必需设置。Required setting for the SQL Server image.

MSSQL_SA_PASSWORDMSSQL_SA_PASSWORD

配置 SA 用户密码。Configure the SA user password.

MSSQL_PIDMSSQL_PID

设置 SQL Server 版本或产品密钥。Set the SQL Server edition or product key. 可能的值包括:Possible values include:

EvaluationEvaluation开发人员Developer

ExpressExpressWebWeb

StandardStandardEnterpriseEnterprise

产品密钥A product key

如果指定产品密钥,则必须采用 #####-#####-#####-#####-##### 格式,其中“#”是数字或字母。If specifying a product key, it must be in the form of #####-#####-#####-#####-#####, where '#' is a number or a letter.

MSSQL_LCIDMSSQL_LCID

设置用于 SQL Server 的语言 ID。Sets the language ID to use for SQL Server. 例如,1036 为法语。For example 1036 is French.

MSSQL_COLLATIONMSSQL_COLLATION

设置 SQL Server 的默认排序规则。Sets the default collation for SQL Server. 这将替代语言 ID (LCID) 到排序规则的默认映射。This overrides the default mapping of language id (LCID) to collation.

MSSQL_MEMORY_LIMIT_MBMSSQL_MEMORY_LIMIT_MB

设置 SQL Server 可以使用的最大内存量(以 MB 为单位)。Sets the maximum amount of memory (in MB) that SQL Server can use. 默认情况下,它为物理内存总量的 80%。By default it is 80% of the total physical memory.

MSSQL_TCP_PORTMSSQL_TCP_PORT

配置 SQL Server 侦听的 TCP 端口(默认为 1433)。Configure the TCP port that SQL Server listens on (default 1433).

MSSQL_IP_ADDRESSMSSQL_IP_ADDRESS

设置 IP 地址。Set the IP address. 目前,IP 地址必须为 IPv4 样式 (0.0.0.0)。Currently, the IP address must be IPv4 style (0.0.0.0).

MSSQL_BACKUP_DIRMSSQL_BACKUP_DIR

设置默认备份目录位置。Set the Default backup directory location.

MSSQL_DATA_DIRMSSQL_DATA_DIR

更改新的 SQL Server 数据库数据文件 (.mdf) 的创建目录。Change the directory where the new SQL Server database data files (.mdf) are created.

MSSQL_LOG_DIRMSSQL_LOG_DIR

更改新的 SQL Server 数据库日志文件 (.ldf) 的创建目录。Change the directory where the new SQL Server database log (.ldf) files are created.

MSSQL_DUMP_DIRMSSQL_DUMP_DIR

更改 SQL Server 存放内存转储和其他故障排除文件的默认目录。Change the directory where SQL Server will deposit the memory dumps and other troubleshooting files by default.

MSSQL_ENABLE_HADRMSSQL_ENABLE_HADR

启用可用性组。Enable Availability Group. 例如,“1”为已启用,“0”为已禁用For example, '1' is enabled, and '0' is disabled

MSSQL_AGENT_ENABLEDMSSQL_AGENT_ENABLED

启用 SQL Server 代理。Enable SQL Server Agent. 例如,“true”为已启用,“false”为已禁用。For example, 'true' is enabled and 'false' is disabled. 默认情况下,代理处于禁用状态。By default, agent is disabled.

MSSQL_MASTER_DATA_FILEMSSQL_MASTER_DATA_FILE

设置主数据库数据文件的位置。Sets the location of the master database data file. 在首次运行 SQL Server 之前,必须将其命名为 master.mdf。Must be named master.mdf until first run of SQL Server.

MSSQL_MASTER_LOG_FILEMSSQL_MASTER_LOG_FILE

设置主数据库日志文件的位置。Sets the location of the master database log file. 在首次运行 SQL Server 之前,必须将其命名为 mastlog.ldf。Must be named mastlog.ldf until first run of SQL Server.

MSSQL_ERROR_LOG_FILEMSSQL_ERROR_LOG_FILE

设置错误日志文件的位置。Sets the location of the errorlog files.

环境变量Environment variable

说明Description

ACCEPT_EULAACCEPT_EULA

将 ACCEPT_EULA 变量设置为任意值,以确认接受 最终用户许可协议。Set the ACCEPT_EULA variable to any value to confirm your acceptance of the End-User Licensing Agreement. SQL Server 映像的必需设置。Required setting for the SQL Server image.

MSSQL_SA_PASSWORDMSSQL_SA_PASSWORD

配置 SA 用户密码。Configure the SA user password.

MSSQL_PIDMSSQL_PID

设置 SQL Server 版本或产品密钥。Set the SQL Server edition or product key. 可能的值包括:Possible values include:

EvaluationEvaluation开发人员Developer

ExpressExpressWebWeb

StandardStandardEnterpriseEnterprise

产品密钥A product key

如果指定产品密钥,则必须采用 #####-#####-#####-#####-##### 格式,其中“#”是数字或字母。If specifying a product key, it must be in the form of #####-#####-#####-#####-#####, where '#' is a number or a letter.

MSSQL_LCIDMSSQL_LCID

设置用于 SQL Server 的语言 ID。Sets the language ID to use for SQL Server. 例如,1036 为法语。For example 1036 is French.

MSSQL_COLLATIONMSSQL_COLLATION

设置 SQL Server 的默认排序规则。Sets the default collation for SQL Server. 这将替代语言 ID (LCID) 到排序规则的默认映射。This overrides the default mapping of language id (LCID) to collation.

MSSQL_MEMORY_LIMIT_MBMSSQL_MEMORY_LIMIT_MB

设置 SQL Server 可以使用的最大内存量(以 MB 为单位)。Sets the maximum amount of memory (in MB) that SQL Server can use. 默认情况下,它为物理内存总量的 80%。By default it is 80% of the total physical memory.

MSSQL_TCP_PORTMSSQL_TCP_PORT

配置 SQL Server 侦听的 TCP 端口(默认为 1433)。Configure the TCP port that SQL Server listens on (default 1433).

MSSQL_IP_ADDRESSMSSQL_IP_ADDRESS

设置 IP 地址。Set the IP address. 目前,IP 地址必须为 IPv4 样式 (0.0.0.0)。Currently, the IP address must be IPv4 style (0.0.0.0).

MSSQL_BACKUP_DIRMSSQL_BACKUP_DIR

设置默认备份目录位置。Set the Default backup directory location.

MSSQL_DATA_DIRMSSQL_DATA_DIR

更改新的 SQL Server 数据库数据文件 (.mdf) 的创建目录。Change the directory where the new SQL Server database data files (.mdf) are created.

MSSQL_LOG_DIRMSSQL_LOG_DIR

更改新的 SQL Server 数据库日志文件 (.ldf) 的创建目录。Change the directory where the new SQL Server database log (.ldf) files are created.

MSSQL_DUMP_DIRMSSQL_DUMP_DIR

更改 SQL Server 存放内存转储和其他故障排除文件的默认目录。Change the directory where SQL Server will deposit the memory dumps and other troubleshooting files by default.

MSSQL_ENABLE_HADRMSSQL_ENABLE_HADR

启用可用性组。Enable Availability Group. 例如,“1”为已启用,“0”为已禁用For example, '1' is enabled, and '0' is disabled

MSSQL_AGENT_ENABLEDMSSQL_AGENT_ENABLED

启用 SQL Server 代理。Enable SQL Server Agent. 例如,“true”为已启用,“false”为已禁用。For example, 'true' is enabled and 'false' is disabled. 默认情况下,代理处于禁用状态。By default, agent is disabled.

MSSQL_MASTER_DATA_FILEMSSQL_MASTER_DATA_FILE

设置主数据库数据文件的位置。Sets the location of the master database data file. 在首次运行 SQL Server 之前,必须将其命名为 master.mdf。Must be named master.mdf until first run of SQL Server.

MSSQL_MASTER_LOG_FILEMSSQL_MASTER_LOG_FILE

设置主数据库日志文件的位置。Sets the location of the master database log file. 在首次运行 SQL Server 之前,必须将其命名为 mastlog.ldf。Must be named mastlog.ldf until first run of SQL Server.

MSSQL_ERROR_LOG_FILEMSSQL_ERROR_LOG_FILE

设置错误日志文件的位置。Sets the location of the errorlog files.

与初始设置配合使用Use with initial setup

此示例使用已配置的环境变量运行 mssql-conf setup。This example runs mssql-conf setup with configured environment variables. 指定了以下环境变量:The following environment variables are specified:

ACCEPT_EULA 接受最终用户许可协议。ACCEPT_EULA accepts the end user license agreement.

MSSQL_PID 指定用于非生产用途的免费许可的 SQL Server Developer Edition。MSSQL_PID specifies the freely licensed Developer Edition of SQL Server for non-production use.

MSSQL_SA_PASSWORD 设置强密码。MSSQL_SA_PASSWORD sets a strong password.

MSSQL_TCP_PORT 将 SQL Server 侦听的 TCP 端口设置为 1234。MSSQL_TCP_PORT sets the TCP port that SQL Server listens on to 1234.

sudo ACCEPT_EULA='Y' MSSQL_PID='Developer' MSSQL_SA_PASSWORD='' MSSQL_TCP_PORT=1234 /opt/mssql/bin/mssql-conf setup

与 Docker 配合使用Use with Docker

此示例 docker 命令使用以下环境变量来创建新的 SQL Server 容器:This example docker command uses the following environment variables to create a new SQL Server container:

ACCEPT_EULA 接受最终用户许可协议。ACCEPT_EULA accepts the end user license agreement.

MSSQL_PID 指定用于非生产用途的免费许可的 SQL Server Developer Edition。MSSQL_PID specifies the freely licensed Developer Edition of SQL Server for non-production use.

MSSQL_SA_PASSWORD 设置强密码。MSSQL_SA_PASSWORD sets a strong password.

MSSQL_TCP_PORT 将 SQL Server 侦听的 TCP 端口设置为 1234。MSSQL_TCP_PORT sets the TCP port that SQL Server listens on to 1234. 这意味着在此示例中,必须使用 -p 1234:1234 命令映射自定义 TCP 端口,而不是将端口 1433(默认)映射到主机端口。This means that instead of mapping port 1433 (default) to a host port, the custom TCP port must be mapped with the -p 1234:1234 command in this example.

如果在 Linux/macOS 上运行 Docker,请将以下语法与单引号配合使用:If you are running Docker on Linux/macOS, use the following syntax with single quotes:

docker run -e ACCEPT_EULA=Y -e MSSQL_PID='Developer' -e MSSQL_SA_PASSWORD='' -e MSSQL_TCP_PORT=1234 -p 1234:1234 -d mcr.microsoft.com/mssql/server:2017-latest

如果在 Windows 上运行 Docker,请将以下语法与双引号配合使用:If you are running Docker on Windows, use the following syntax with double quotes:

docker run -e ACCEPT_EULA=Y -e MSSQL_PID="Developer" -e MSSQL_SA_PASSWORD="" -e MSSQL_TCP_PORT=1234 -p 1234:1234 -d mcr.microsoft.com/mssql/server:2017-latest

备注

在容器中运行生产版本的过程略有不同。The process for running production editions in containers is slightly different. 有关详细信息,请参阅运行生产容器映像。

如果在 Linux/macOS 上运行 Docker,请将以下语法与单引号配合使用:If you are running Docker on Linux/macOS, use the following syntax with single quotes:

docker run -e ACCEPT_EULA=Y -e MSSQL_PID='Developer' -e MSSQL_SA_PASSWORD='' -e MSSQL_TCP_PORT=1234 -p 1234:1234 -d mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04

如果在 Windows 上运行 Docker,请将以下语法与双引号配合使用:If you are running Docker on Windows, use the following syntax with double quotes:

docker run -e ACCEPT_EULA=Y -e MSSQL_PID="Developer" -e MSSQL_SA_PASSWORD="" -e MSSQL_TCP_PORT=1234 -p 1234:1234 -d mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04

后续步骤Next steps

有关如何在 Linux 上安装和运行 SQL Server 的详细信息,请参阅在 Linux 上安装 SQL Server。For more information on how to install and run SQL Server on Linux, see Install SQL Server on Linux.