6.2.4 Specifying Account Names指定帐户名

MySQL account names consist of a user name and a host name, which enables creation of distinct accounts for users with the same user name who connect from different hosts. This section describes the syntax for account names, including special values and wildcard rules.MySQL帐户名由用户名和主机名组成,这使得能够为从不同主机连接的具有相同用户名的用户创建不同的帐户。本节介绍帐户名的语法,包括特殊值和通配符规则。

In most respects, account names are similar to MySQL role names, with some differences described at Section 6.2.5, “Specifying Role Names”.在大多数方面,帐户名与MySQL角色名相似,但在第6.2.5节,“指定角色名”中描述了一些差异。

Account names appear in SQL statements such as CREATE USER, GRANT, and SET PASSWORD and follow these rules:帐户名出现在SQL语句中,如CREATE USERGRANTSET PASSWORD,并遵循以下规则:

MySQL stores account names in grant tables in the mysql system database using separate columns for the user name and host name parts:MySQL将帐户名存储在mysql系统数据库的授权表中,用户名和主机名部分使用单独的列:

For additional detail about the properties of user names and host names as stored in the grant tables, such as maximum length, see Grant Table Scope Column Properties.有关存储在授权表中的用户名和主机名的属性(如最大长度)的更多详细信息,请参阅授权表作用域列属性

User names and host names have certain special values or wildcard conventions, as described following.用户名和主机名具有某些特殊值或通配符约定,如下所述。

The user name part of an account name is either a nonblank value that literally matches the user name for incoming connection attempts, or a blank value (the empty string) that matches any user name. 帐户名的用户名部分要么是与传入连接尝试的用户名字面匹配的非空值,要么是与任何用户名匹配的空值(空字符串)。An account with a blank user name is an anonymous user. To specify an anonymous user in SQL statements, use a quoted empty user name part, such as ''@'localhost'.用户名为空的帐户是匿名用户。若要在SQL语句中指定匿名用户,请使用引号括起来的空用户名部分,例如''@'localhost'

The host name part of an account name can take many forms, and wildcards are permitted:帐户名的主机名部分可以采用多种形式,并且允许使用通配符:

The server performs matching of host values in account names against the client host using the value returned by the system DNS resolver for the client host name or IP address. 服务器使用系统DNS解析器为客户端主机名或IP地址返回的值,将帐户名中的主机值与客户端主机进行匹配。Except in the case that the account host value is specified using netmask notation, the server performs this comparison as a string match, even for an account host value given as an IP address. 除了使用网掩码表示法指定帐户主机值的情况外,服务器还会将此比较作为字符串匹配来执行,即使对于作为IP地址给出的帐户主机值也是如此。This means that you should specify account host values in the same format used by DNS. Here are examples of problems to watch out for:这意味着您应该以DNS使用的相同格式指定帐户主机值。以下是需要注意的问题示例:

To avoid problems like these, it is advisable to check the format in which your DNS returns host names and addresses. Use values in the same format in MySQL account names.为了避免此类问题,建议检查DNS返回主机名和地址的格式。在MySQL帐户名中使用相同格式的值。