MySQL 角色名称指的是角色,即一组具有名称的权限集合。有关角色使用示例,请参见 第 8.2.10 节,“使用角色”。MySQL role names refer to roles, which are named collections of privileges. For role usage examples, see Section 8.2.10, “Using Roles”.
角色名称的语法和语义类似于账户名称;请参见 第 8.2.4 节,“指定账户名称”。存储在授权表中时,它们具有与账户名称相同的属性,这些属性在 授权表作用域列属性 中有描述。Role names have syntax and semantics similar to account names; see Section 8.2.4, “Specifying Account Names”. As stored in the grant tables, they have the same properties as account names, which are described in Grant Table Scope Column Properties.
角色名称在以下方面与账户名称不同:Role names differ from account names in these respects:
角色名称中的用户部分不能为空。因此,没有“匿名角色”类似于“匿名用户”The user part of role names cannot be blank. Thus, there is no “anonymous role” analogous to the concept of “anonymous user.”
As for an account name, omitting the host part of a role name results in a host part of
'%'. But unlike'%'in an account name, a host part of'%'in a role name has no wildcard properties. For example, for a name'me'@'%'used as a role name, the host part ('%') is just a literal value; it has no “的有效值和 400 中的较大值;也就是说”匹配属性的任何主机。As for an account name, omitting the host part of a role name results in a host part of'%'. But unlike'%'in an account name, a host part of'%'in a role name has no wildcard properties. For example, for a name'me'@'%'used as a role name, the host part ('%') is just a literal value; it has no “any host” matching property.角色名称的主机部分中的子网掩码表示法没有意义。Netmask notation in the host part of a role name has no significance.
在多种情况下,账户名称允许使用
CURRENT_USER()。而角色名称则不允许。An account name is permitted to beCURRENT_USER()in several contexts. A role name is not.
mysql.user 系统表中的一行可以同时作为账户和角色使用。在这种情况下,任何与特殊用户或主机名称匹配的属性均不适用于该名称作为角色名称使用的上下文。例如,你不能执行以下语句并期望它使用所有用户部分为 myrole 且主机名为任意的角色来设置当前会话角色:It is possible for a row in the mysql.user
system table to serve as both an account and a role. In this case,
any special user or host name matching properties do not apply in
contexts for which the name is used as a role name. For example,
you cannot execute the following statement with the expectation
that it sets the current session roles using all roles that have a
user part of myrole and any host name:
SET ROLE 'myrole'@'%';
相反,该语句会将会话的活动角色设置为名称恰好为 'myrole'@'%' 的角色。Instead, the statement sets the active role for the session to the
role with exactly the name 'myrole'@'%'.
因此,角色名称通常只使用用户名部分来指定,而将主机名部分隐式设为'%'。如果您打算创建一个既作为角色又作为允许从指定主机连接的用户账户的名称,则指定一个非'%'的主机部分可能会很有用。For this reason, role names are often specified using only the
user name part and letting the host name part implicitly be
'%'. Specifying a role with a
non-'%' host part can be useful if you intend
to create a name that works both as a role an as a user account
that is permitted to connect from the given host.