6.2.5 Specifying Role Names指定角色名称

MySQL role names refer to roles, which are named collections of privileges. For role usage examples, see Section 6.2.10, “Using Roles”.MySQL角色名称是指角色,这些角色被命名为特权集合。有关角色使用示例,请参阅第6.2.10节,“使用角色”

Role names have syntax and semantics similar to account names; see Section 6.2.4, “Specifying Account Names”. 角色名称的语法和语义与帐户名称相似;请参阅第6.2.4节,“指定帐户名”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:角色名称在以下方面与帐户名称不同:

It is possible for a row in the mysql.user system table to serve as both an account and a role. mysql.user系统表中的一行可以同时用作帐户和角色。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:例如,您不能执行以下语句,并期望它使用具有myrole用户部分和任何主机名的所有角色来设置当前会话角色:

SET ROLE 'myrole'@'%';

Instead, the statement sets the active role for the session to the role with exactly the name 'myrole'@'%'.相反,该语句将会话的活动角色设置为名为'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.如果您打算创建一个既可以作为角色又可以作为允许从给定主机连接的用户帐户的名称,那么指定一个具有非'%'主机部分的角色可能会很有用。