Windows pluggable authentication is an extension included in MySQL Enterprise Edition, a commercial product. Windows可插拔身份验证是商业产品MySQL Enterprise Edition中包含的扩展。To learn more about commercial products, see https://www.mysql.com/products/.要了解有关商业产品的更多信息,请参阅https://www.mysql.com/products/。
MySQL Enterprise Edition for Windows supports an authentication method that performs external authentication on Windows, enabling MySQL Server to use native Windows services to authenticate client connections. Users who have logged in to Windows can connect from MySQL client programs to the server based on the information in their environment without specifying an additional password.MySQL Enterprise Edition for Windows支持在Windows上执行外部身份验证的身份验证方法,使MySQL Server能够使用本机Windows服务对客户端连接进行身份验证。登录到Windows的用户可以根据其环境中的信息从MySQL客户端程序连接到服务器,而无需指定额外的密码。
The client and server exchange data packets in the authentication handshake. As a result of this exchange, the server creates a security context object that represents the identity of the client in the Windows OS. This identity includes the name of the client account. Windows pluggable authentication uses the identity of the client to check whether it is a given account or a member of a group. 客户端和服务器在身份验证握手中交换数据包。作为此交换的结果,服务器创建了一个安全上下文对象,该对象表示Windows操作系统中客户端的身份。此标识包括客户端帐户的名称。Windows可插拔身份验证使用客户端的身份来检查它是给定的帐户还是组的成员。By default, negotiation uses Kerberos to authenticate, then NTLM if Kerberos is unavailable.默认情况下,协商使用Kerberos进行身份验证,如果Kerberos不可用,则使用NTLM。
Windows pluggable authentication provides these capabilities:Windows可插拔身份验证提供了以下功能:
External authentication: Windows authentication enables MySQL Server to accept connections from users defined outside the MySQL grant tables who have logged in to Windows.外部身份验证:Windows身份验证使MySQL Server能够接受来自MySQL授权表之外已登录到Windows的用户的连接。
Proxy user support: Windows authentication can return to MySQL a user name different from the external user name passed by the client program. This means that the plugin can return the MySQL user that defines the privileges the external Windows-authenticated user should have. 代理用户支持:Windows身份验证可以向MySQL返回与客户端程序传递的外部用户名不同的用户名。这意味着插件可以返回MySQL用户,该用户定义了外部Windows身份验证用户应具有的权限。For example, a Windows user named 例如,名为joe
can connect and have the privileges of a MySQL user named developer
.joe
的Windows用户可以连接并拥有名为developer
的MySQL用户的权限。
The following table shows the plugin and library file names. The file must be located in the directory named by the 下表显示了插件和库文件名。文件必须位于plugin_dir
system variable.plugin_dir
系统变量命名的目录中。
Table 6.17 Plugin and Library Names for Windows AuthenticationWindows身份验证的插件和库名称
authentication_windows | |
authentication_windows_client | |
authentication_windows.dll |
The library file includes only the server-side plugin. The client-side plugin is built into the 库文件仅包含服务器端插件。客户端插件内置于libmysqlclient
client library.libmysqlclient
客户端库中。
The server-side Windows authentication plugin is included only in MySQL Enterprise Edition. It is not included in MySQL community distributions. 服务器端的Windows身份验证插件仅包含在MySQL企业版中。它不包含在MySQL社区发行版中。The client-side plugin is included in all distributions, including community distributions. This permits clients from any distribution to connect to a server that has the server-side plugin loaded.客户端插件包含在所有发行版中,包括社区发行版。这允许来自任何发行版的客户端连接到加载了服务器端插件的服务器。
The Windows authentication plugin is supported on any version of Windows supported by MySQL 8.0 (see https://www.mysql.com/support/supportedplatforms/database.html).MySQL 8.0支持的任何版本的Windows都支持Windows身份验证插件(请参阅https://www.mysql.com/support/supportedplatforms/database.html)。
The following sections provide installation and usage information specific to Windows pluggable authentication:以下部分提供了特定于Windows可插拔身份验证的安装和使用信息:
For general information about pluggable authentication in MySQL, see Section 6.2.17, “Pluggable Authentication”. For proxy user information, see Section 6.2.18, “Proxy Users”.有关MySQL中可插拔身份验证的一般信息,请参阅第6.2.17节,“可插拔身份认证”。有关代理用户信息,请参阅第6.2.18节,“代理用户”。
This section describes how to install the Windows authentication plugin. For general information about installing plugins, see Section 5.6.1, “Installing and Uninstalling Plugins”.本节介绍如何安装Windows身份验证插件。有关安装插件的一般信息,请参阅第5.6.1节,“安装和卸载插件”。
To be usable by the server, the plugin library file must be located in the MySQL plugin directory (the directory named by the 为了让服务器使用,插件库文件必须位于MySQL插件目录(由plugin_dir
system variable). plugin_dir
系统变量命名的目录)中。If necessary, configure the plugin directory location by setting the value of 如有必要,在服务器启动时通过设置plugin_dir
at server startup.plugin_dir
的值来配置插件目录位置。
To load the plugin at server startup, use the 要在服务器启动时加载插件,请使用--plugin-load-add
option to name the library file that contains it. --plugin-load-add
选项命名包含它的库文件。With this plugin-loading method, the option must be given each time the server starts. For example, put these lines in the server 使用此插件加载方法,每次服务器启动时都必须给出该选项。例如,将以下行放入服务器my.cnf
file:my.cnf
文件中:
[mysqld] plugin-load-add=authentication_windows.dll
After modifying 修改my.cnf
, restart the server to cause the new settings to take effect.my.cnf
后,重新启动服务器以使新设置生效。
Alternatively, to load the plugin at runtime, use this statement:或者,要在运行时加载插件,请使用以下语句:
INSTALL PLUGIN authentication_windows SONAME 'authentication_windows.dll';
INSTALL PLUGIN
loads the plugin immediately, and also registers it in the mysql.plugins
system table to cause the server to load it for each subsequent normal startup without the need for --plugin-load-add
.INSTALL PLUGIN
会立即加载插件,并将其注册到mysql.plugins
系统表中,以便服务器在每次后续正常启动时加载它,而不需要--plugin-load-add
。
To verify plugin installation, examine the 要验证插件安装,请检查INFORMATION_SCHEMA.PLUGINS
table or use the SHOW PLUGINS
statement (see Section 5.6.2, “Obtaining Server Plugin Information”). For example:INFORMATION_SCHEMA.PLUGINS
表或使用SHOW PLUGINS
语句(请参阅第5.6.2节,“获取服务器插件信息”)。例如:
mysql>SELECT PLUGIN_NAME, PLUGIN_STATUS
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_NAME LIKE '%windows%';
+------------------------+---------------+ | PLUGIN_NAME | PLUGIN_STATUS | +------------------------+---------------+ | authentication_windows | ACTIVE | +------------------------+---------------+
If the plugin fails to initialize, check the server error log for diagnostic messages.如果插件初始化失败,请检查服务器错误日志中的诊断消息。
To associate MySQL accounts with the Windows authentication plugin, see Using Windows Pluggable Authentication. 要将MySQL帐户与Windows身份验证插件相关联,请参阅使用Windows可插拔身份验证。Additional plugin control is provided by the 附加插件控制由authentication_windows_use_principal_name
and authentication_windows_log_level
system variables. authentication_windows_use_principal_name
和authentication_windows_log_level
系统变量提供。See Section 5.1.8, “Server System Variables”.请参阅第5.1.8节,“服务器系统变量”。
The method used to uninstall the Windows authentication plugin depends on how you installed it:卸载Windows身份验证插件的方法取决于您的安装方式:
If you installed the plugin at server startup using a 如果您在服务器启动时使用--plugin-load-add
option, restart the server without the option.--plugin-load-add
选项安装了插件,请在不使用该选项的情况下重新启动服务器。
If you installed the plugin at runtime using an 如果您在运行时使用INSTALL PLUGIN
statement, it remains installed across server restarts. INSTALL PLUGIN
语句安装了插件,则它在服务器重新启动时仍会安装。To uninstall it, use 要卸载它,请使用UNINSTALL PLUGIN
:UNINSTALL PLUGIN
:
UNINSTALL PLUGIN authentication_windows;
In addition, remove any startup options that set Windows plugin-related system variables.此外,删除任何设置Windows插件相关系统变量的启动选项。
The Windows authentication plugin supports the use of MySQL accounts such that users who have logged in to Windows can connect to the MySQL server without having to specify an additional password. Windows身份验证插件支持使用MySQL帐户,这样登录到Windows的用户就可以连接到MySQL服务器,而无需指定额外的密码。It is assumed that the server is running with the server-side plugin enabled, as described in Installing Windows Pluggable Authentication. 假设服务器在启用服务器端插件的情况下运行,如安装Windows可插拔身份验证中所述。Once the DBA has enabled the server-side plugin and set up accounts to use it, clients can connect using those accounts with no other setup required on their part.一旦DBA启用了服务器端插件并设置了使用它的帐户,客户端就可以使用这些帐户进行连接,而不需要进行其他设置。
To refer to the Windows authentication plugin in the 要在IDENTIFIED WITH
clause of a CREATE USER
statement, use the name authentication_windows
. CREATE USER
语句的IDENTIFIED WITH
子句中引用Windows身份验证插件,请使用名称authentication_Windows
。Suppose that the Windows users 假设应该允许Windows用户Rafal
and Tasha
should be permitted to connect to MySQL, as well as any users in the Administrators
or Power Users
group. Rafal
和Tasha
以及Administrators
或Power Users
组中的任何用户连接到MySQL。To set this up, create a MySQL account named 要设置此设置,请创建一个名为sql_admin
that uses the Windows plugin for authentication:sql_admin
的MySQL帐户,该帐户使用Windows插件进行身份验证:
CREATE USER sql_admin IDENTIFIED WITH authentication_windows AS 'Rafal, Tasha, Administrators, "Power Users"';
The plugin name is 插件名称为authentication_windows
. The string following the AS
keyword is the authentication string. authentication_windows
。AS
关键字后面的字符串是身份验证字符串。It specifies that the Windows users named 它指定允许名为Rafal
or Tasha
are permitted to authenticate to the server as the MySQL user sql_admin
, as are any Windows users in the Administrators
or Power Users
group. Rafal
或Tasha
的Windows用户以MySQL用户sql_admin
的身份向服务器进行身份验证,管理员或高级用户组中的任何Windows用户也是如此。The latter group name contains a space, so it must be quoted with double quote characters.后一个组名包含空格,因此必须用双引号括起来。
After you create the 创建sql_admin
account, a user who has logged in to Windows can attempt to connect to the server using that account:sql_admin
帐户后,登录到Windows的用户可以尝试使用该帐户连接到服务器:
C:\> mysql --user=sql_admin
No password is required here. 此处不需要密码。The authentication_windows
plugin uses the Windows security API to check which Windows user is connecting. authentication_windows
插件使用windows安全API来检查正在连接的windows用户。If that user is named 如果该用户名为Rafal
or Tasha
, or is a member of the Administrators
or Power Users
group, the server grants access and the client is authenticated as sql_admin
and has whatever privileges are granted to the sql_admin
account. Rafal
或Tasha
,或者是Administrators
或Power Users组的成员,则服务器将授予访问权限,客户端将通过sql_admin
身份验证,并具有授予sql_admin
帐户的任何权限。Otherwise, the server denies access.否则,服务器将拒绝访问。
Authentication string syntax for the Windows authentication plugin follows these rules:Windows身份验证插件的身份验证字符串语法遵循以下规则:
The string consists of one or more user mappings separated by commas.该字符串由一个或多个用逗号分隔的用户映射组成。
Each user mapping associates a Windows user or group name with a MySQL user name:每个用户映射都将Windows用户或组名与MySQL用户名相关联:
win_user_or_group_name=mysql_user_name
win_user_or_group_name
For the latter syntax, with no 对于后一种语法,在没有给出mysql_user_name
value given, the implicit value is the MySQL user created by the CREATE USER
statement. Thus, these statements are equivalent:mysql_user_name
值的情况下,隐式值是CREATE USER
语句创建的mysql用户。因此,这些陈述是等价的:
CREATE USER sql_admin IDENTIFIED WITH authentication_windows AS 'Rafal, Tasha, Administrators, "Power Users"'; CREATE USER sql_admin IDENTIFIED WITH authentication_windows AS 'Rafal=sql_admin, Tasha=sql_admin, Administrators=sql_admin, "Power Users"=sql_admin';
Each backslash character (值中的每个反斜杠字符(\
) in a value must be doubled because backslash is the escape character in MySQL strings.\
)都必须加倍,因为反斜杠是MySQL字符串中的转义符。
Leading and trailing spaces not inside double quotation marks are ignored.不在双引号内的前导和尾随空格将被忽略。
Unquoted 未加引号的win_user_or_group_name
and mysql_user_name
values can contain anything except equal sign, comma, or space.win_user_or_group_name
和mysql_user_name
值可以包含除等号、逗号或空格以外的任何内容。
If a 如果win_user_or_group_name
and or mysql_user_name
value is quoted with double quotation marks, everything between the quotation marks is part of the value. win_user_or_group_name
和/或mysql_user_name
值用双引号括起来,则引号之间的所有内容都是该值的一部分。This is necessary, for example, if the name contains space characters. All characters within double quotes are legal except double quotation mark and backslash. To include either character, escape it with a backslash.例如,如果名称包含空格字符,则这是必要的。双引号内的所有字符都是合法的,双引号和反斜杠除外。要包含任一字符,请用反斜杠转义。
win_user_or_group_name
values use conventional syntax for Windows principals, either local or in a domain. Examples (note the doubling of backslashes):win_user_or_group_name
值对Windows主体(本地或域中)使用常规语法。示例(注意睫毛加倍):
domain\\user .\\user domain\\group .\\group BUILTIN\\WellKnownGroup
When invoked by the server to authenticate a client, the plugin scans the authentication string left to right for a user or group match to the Windows user. 当服务器调用插件对客户端进行身份验证时,插件会从左到右扫描身份验证字符串,寻找与Windows用户匹配的用户或组。If there is a match, the plugin returns the corresponding 如果匹配,插件会将相应的mysql_user_name
to the MySQL server. If there is no match, authentication fails.mysql_user_name
返回给mysql服务器。如果不匹配,则身份验证失败。
A user name match takes preference over a group name match. Suppose that the Windows user named 用户名匹配优先于组名匹配。假设名为win_user
is a member of win_group
and the authentication string looks like this:win_user
的Windows用户是win_group
的成员,身份验证字符串如下:
'win_group = sql_user1, win_user = sql_user2'
When 当win_user
connects to the MySQL server, there is a match both to win_group
and to win_user
. win_user
连接到MySQL服务器时,win_group
和win_user
都匹配。The plugin authenticates the user as 该插件将用户身份验证为sql_user2
because the more-specific user match takes precedence over the group match, even though the group is listed first in the authentication string.sql_user2
,因为更具体的用户匹配优先于组匹配,即使组在身份验证字符串中列在第一位。
Windows authentication always works for connections from the same computer on which the server is running. For cross-computer connections, both computers must be registered with Windows Active Directory. Windows身份验证始终适用于来自运行服务器的同一台计算机的连接。对于跨计算机连接,两台计算机都必须向Windows 活动目录注册。If they are in the same Windows domain, it is unnecessary to specify a domain name. It is also possible to permit connections from a different domain, as in this example:如果它们在同一个Windows域中,则不需要指定域名。也可以允许来自不同域的连接,如本例所示:
CREATE USER sql_accounting IDENTIFIED WITH authentication_windows AS 'SomeDomain\\Accounting';
Here 这里SomeDomain
is the name of the other domain. The backslash character is doubled because it is the MySQL escape character within strings.SomeDomain
是另一个域的名称。反斜杠字符被加倍,因为它是字符串中的MySQL转义符。
MySQL supports the concept of proxy users whereby a client can connect and authenticate to the MySQL server using one account but while connected has the privileges of another account (see Section 6.2.18, “Proxy Users”). MySQL支持代理用户的概念,客户端可以使用一个帐户连接并验证MySQL服务器,但在连接时拥有另一个帐户的权限(参阅第6.2.18节,“代理用户”)。Suppose that you want Windows users to connect using a single user name but be mapped based on their Windows user and group names onto specific MySQL accounts as follows:假设您希望Windows用户使用单个用户名连接,但根据他们的Windows用户名和组名映射到特定的MySQL帐户,如下所示:
The local_user
and MyDomain\domain_user
local and domain Windows users should map to the local_wlad
MySQL account.local_user
和MyDomain\domain_user
本地和域Windows用户应映射到local_wlad
MySQL帐户。
Users in the MyDomain\Developers
domain group should map to the local_dev
MySQL account.MyDomain\Developers
域组中的用户应映射到local_dev
MySQL帐户。
Local machine administrators should map to the 本地计算机管理员应映射到local_admin
MySQL account.local_admin
MySQL帐户。
To set this up, create a proxy account for Windows users to connect to, and configure this account so that users and groups map to the appropriate MySQL accounts (要设置此设置,请为Windows用户创建一个代理帐户进行连接,并配置此帐户,以便用户和组映射到相应的MySQL帐户(local_wlad
, local_dev
, local_admin
). local_wlad
、local_dev
、local_admin
)。In addition, grant the MySQL accounts the privileges appropriate to the operations they need to perform. 此外,授予MySQL帐户与其需要执行的操作相对应的权限。The following instructions use 以下说明使用win_proxy
as the proxy account, and local_wlad
, local_dev
, and local_admin
as the proxied accounts.win_proxy
作为代理帐户,使用local_wlad
、local_dev
和local_admin
作为代理帐户。
Create the proxy MySQL account:创建MySQL代理帐户:
CREATE USER win_proxy IDENTIFIED WITH authentication_windows AS 'local_user = local_wlad, MyDomain\\domain_user = local_wlad, MyDomain\\Developers = local_dev, BUILTIN\\Administrators = local_admin';
For proxying to work, the proxied accounts must exist, so create them:为了使代理工作,代理帐户必须存在,因此创建它们:
CREATE USER local_wlad IDENTIFIED WITH mysql_no_login; CREATE USER local_dev IDENTIFIED WITH mysql_no_login; CREATE USER local_admin IDENTIFIED WITH mysql_no_login;
The proxied accounts use the 代理帐户使用mysql_no_login
authentication plugin to prevent clients from using the accounts to log in directly to the MySQL server. mysql_no_login
身份验证插件来防止客户端使用帐户直接登录mysql服务器。Instead, users who authenticate using Windows are expected to use the 相反,使用Windows进行身份验证的用户应该使用win_proxy
proxy account. win_proxy
代理帐户。(This assumes that the plugin is installed. For instructions, see Section 6.4.1.8, “No-Login Pluggable Authentication”.) (这假设插件已安装。有关说明,请参阅第6.4.1.8节,“无登录可插拔身份验证”。)For alternative methods of protecting proxied accounts against direct use, see Preventing Direct Login to Proxied Accounts.有关保护代理帐户免受直接使用的替代方法,请参阅防止直接登录代理帐户。
You should also execute 您还应该执行GRANT
statements (not shown) that grant each proxied account the privileges required for MySQL access.GRANT
语句(未显示),授予每个代理帐户访问MySQL所需的权限。
Grant to the proxy account the 为每个PROXY
privilege for each proxied account:PROXY
帐户授予代理权限:
GRANT PROXY ON local_wlad TO win_proxy; GRANT PROXY ON local_dev TO win_proxy; GRANT PROXY ON local_admin TO win_proxy;
Now the Windows users 现在,Windows用户local_user
and MyDomain\domain_user
can connect to the MySQL server as win_proxy
and when authenticated have the privileges of the account given in the authentication string (in this case, local_wlad
). local_user
和MyDomain\domain_user
可以作为win_proxy连接到MySQL服务器,并且在经过身份验证后具有身份验证字符串中给出的帐户的权限(在本例中为local_wlad
)。A user in the MyDomain\Developers
group who connects as win_proxy
has the privileges of the local_dev
account. A user in the BUILTIN\Administrators
group has the privileges of the local_admin
account.MyDomain\Developers
组中以win_proxy
身份连接的用户具有local_dev
帐户的权限。BUILTIN\Administrators
组中的用户具有local_admin帐户的权限。
To configure authentication so that all Windows users who do not have their own MySQL account go through a proxy account, substitute the default proxy account (要配置身份验证,以便所有没有自己MySQL帐户的Windows用户都通过代理帐户,请在前面的说明中将''@''
) for win_proxy
in the preceding instructions. win_proxy
替换为默认代理帐户(''@''
)。For information about default proxy accounts, see Section 6.2.18, “Proxy Users”.有关默认代理帐户的信息,请参阅第6.2.18节,“代理用户”。
If your MySQL installation has anonymous users, they might conflict with the default proxy user. 如果你的MySQL安装有匿名用户,他们可能会与默认代理用户冲突。For more information about this issue, and ways of dealing with it, see Default Proxy User and Anonymous User Conflicts.有关此问题的更多信息以及处理方法,请参阅默认代理用户和匿名用户冲突。
To use the Windows authentication plugin with Connector/NET connection strings in Connector/NET 6.4.4 and higher, see Using the Windows Native Authentication Plugin.要在Connector/NET 6.4.4及更高版本中将Windows身份验证插件与Connector/NET连接字符串一起使用,请参阅使用Windows本机身份验证插件。