13.7.1.9 SET DEFAULT ROLE Statement语句

SET DEFAULT ROLE
    {NONE | ALL | role [, role ] ...}
    TO user [, user ] ...

For each user named immediately after the TO keyword, this statement defines which roles become active when the user connects to the server and authenticates, or when the user executes the SET ROLE DEFAULT statement during a session.对于紧跟在TO关键字之后命名的每个user,该语句定义了当用户连接到服务器并进行身份验证时,或者当用户在会话期间执行SET ROLE DEFAULT语句时,哪些角色变为活动角色。

SET DEFAULT ROLE is alternative syntax for ALTER USER ... DEFAULT ROLE (see Section 13.7.1.1, “ALTER USER Statement”). SET DEFAULT ROLEALTER USER ... DEFAULT ROLE的替代语法(见第13.7.1.1节,“ALTER USER语句”)。However, ALTER USER can set the default for only a single user, whereas SET DEFAULT ROLE can set the default for multiple users. 但是,ALTER USER只能为单个用户设置默认值,而SET DEFAULT ROLE可以为多个用户设置默认值。On the other hand, you can specify CURRENT_USER as the user name for the ALTER USER statement, whereas you cannot for SET DEFAULT ROLE.另一方面,您可以为ALTER USER语句指定CURRENT_USER作为用户名,而不能为SET DEFAULT ROLE指定用户名。

SET DEFAULT ROLE requires these privileges:需要以下权限:

Each role name uses the format described in Section 6.2.5, “Specifying Role Names”. For example:每个角色名称使用第6.2.5节,“指定角色名称”中描述的格式。例如:

SET DEFAULT ROLE 'admin', 'developer' TO 'joe'@'10.0.0.1';

The host name part of the role name, if omitted, defaults to '%'.角色名的主机名部分(如果省略)默认为'%'

The clause following the DEFAULT ROLE keywords permits these values:DEFAULT ROLE关键字后面的子句允许以下值:

Note注意

SET DEFAULT ROLE and SET ROLE DEFAULT are different statements:是不同的语句:

  • SET DEFAULT ROLE defines which account roles to activate by default within account sessions.定义默认情况下要在帐户会话中激活的帐户角色。

  • SET ROLE DEFAULT sets the active roles within the current session to the current account default roles.将当前会话中的活动角色设置为当前帐户默认角色。

For role usage examples, see Section 6.2.10, “Using Roles”.有关角色使用示例,请参阅第6.2.10节,“使用角色”