SET ROLE { DEFAULT | NONE | ALL | ALL EXCEPTrole
[,role
] ... |role
[,role
] ... }
SET ROLE
modifies the current user's effective privileges within the current session by specifying which of its granted roles are active. SET ROLE
通过指定当前用户授予的哪些角色处于活动状态,修改当前用户在当前会话中的有效权限。Granted roles include those granted explicitly to the user and those named in the 已授予的角色包括明确授予用户的角色,以及在mandatory_roles
system variable value.mandatory_roles
系统变量值中命名的角色。
Examples:
SET ROLE DEFAULT; SET ROLE 'role1', 'role2'; SET ROLE ALL; SET ROLE ALL EXCEPT 'role1', 'role2';
Each role name uses the format described in Section 6.2.5, “Specifying Role Names”. 每个角色名称使用第6.2.5节,“指定角色名称”中描述的格式。The host name part of the role name, if omitted, defaults to 角色名的主机名部分(如果省略)默认为'%'
.'%'
。
Privileges that the user has been granted directly (rather than through roles) remain unaffected by changes to the active roles.直接(而不是通过角色)授予用户的权限不受活动角色更改的影响。
The statement permits these role specifiers:该语句允许以下角色说明符:
DEFAULT
: Activate the account default roles. :激活帐户默认角色。Default roles are those specified with 默认角色是使用SET DEFAULT ROLE
.SET DEFAULT ROLE
指定的角色。
When a user connects to the server and authenticates successfully, the server determines which roles to activate as the default roles. 当用户连接到服务器并成功进行身份验证时,服务器将确定要激活哪些角色作为默认角色。If the 如果启用了activate_all_roles_on_login
system variable is enabled, the server activates all granted roles. activate_all_roles_on_login
系统变量,服务器将激活所有授予的角色。Otherwise, the server executes 否则,服务器将隐式执行SET ROLE DEFAULT
implicitly. SET ROLE DEFAULT
。The server activates only default roles that can be activated. 服务器只激活可以激活的默认角色。The server writes warnings to its error log for default roles that cannot be activated, but the client receives no warnings.服务器将无法激活的默认角色的警告写入其错误日志,但客户端未收到任何警告。
If a user executes 如果用户在会话期间执行SET ROLE DEFAULT
during a session, an error occurs if any default role cannot be activated (for example, if it does not exist or is not granted to the user). SET ROLE DEFAULT
,则如果无法激活任何默认角色(例如,如果该角色不存在或未授予该用户),则会发生错误。In this case, the current active roles are not changed.在这种情况下,当前的活动角色不会更改。
NONE
: Set the active roles to :将活动角色设置为NONE
(no active roles).NONE
(无活动角色)。
ALL
: Activate all roles granted to the account.:激活授予该帐户的所有角色。
ALL EXCEPT
role
[, role
] ...: Activate all roles granted to the account except those named. :激活授予帐户的所有角色,但命名的角色除外。The named roles need not exist or be granted to the account.指定的角色不需要存在,也不需要授予该帐户。
role
[, role
] ...: Activate the named roles, which must be granted to the account.:激活必须授予帐户的命名角色。
SET DEFAULT ROLE
and SET ROLE DEFAULT
are different statements:SET DEFAULT ROLE
和SET ROLE DEFAULT
是不同的语句:
SET DEFAULT ROLE
defines which account roles to activate by default within account sessions.SET DEFAULT ROLE
定义默认情况下在帐户会话中激活哪些帐户角色。
SET ROLE DEFAULT
sets the active roles within the current session to the current account default roles.SET ROLE DEFAULT
将当前会话中的活动角色设置为当前帐户默认角色。
For role usage examples, see Section 6.2.10, “Using Roles”.有关角色使用示例,请参阅第6.2.10节,“使用角色”。