授予 MySQL 帐户的权限决定了该帐户可以执行哪些操作。MySQL 权限在其适用的上下文和不同操作级别上有所不同:The privileges granted to a MySQL account determine which operations the account can perform. MySQL privileges differ in the contexts in which they apply and at different levels of operation:
管理权限使用户能够管理 MySQL 服务器的操作。这些权限是全局的,因为它们并不针对特定数据库。Administrative privileges enable users to manage operation of the MySQL server. These privileges are global because they are not specific to a particular database.
数据库权限适用于某个数据库及其内部的所有对象。这些权限可以针对特定数据库授予,也可以全局授予,以便适用于所有数据库。Database privileges apply to a database and to all objects within it. These privileges can be granted for specific databases, or globally so that they apply to all databases.
针对数据库对象(例如表、索引、视图和存储过程)的权限可以针对数据库中的特定对象授予,也可以针对数据库中某类类型的所有对象(例如数据库中的所有表)授予,或者全局授予,以适用于所有数据库中该类型的所有对象。Privileges for database objects such as tables, indexes, views, and stored routines can be granted for specific objects within a database, for all objects of a given type within a database (for example, all tables in a database), or globally for all objects of a given type in all databases.
权限在是否为静态(内置于服务器)或动态(在运行时定义)方面也有所不同。权限是静态还是动态会影响其被授予用户账户和角色的可用性。有关静态权限和动态权限之间差异的信息,请参阅 静态与动态权限。Privileges also differ in terms of whether they are static (built in to the server) or dynamic (defined at runtime). Whether a privilege is static or dynamic affects its availability to be granted to user accounts and roles. For information about the differences between static and dynamic privileges, see Static Versus Dynamic Privileges.)
关于账户权限的信息存储在 mysql 系统数据库的授权表中。有关这些表的结构和内容的描述,请参见 第 8.2.3 节,“授权表”。MySQL 服务器在启动时会将授权表的内容读取到内存中,并在 第 8.2.13 节,“权限更改生效时间” 指示的情况下重新加载它们。服务器基于授权表的内存副本进行访问控制决策。Information about account privileges is stored in the grant tables
in the mysql system database. For a description
of the structure and contents of these tables, see
Section 8.2.3, “Grant Tables”. The MySQL server reads the
contents of the grant tables into memory when it starts, and
reloads them under the circumstances indicated in
Section 8.2.13, “When Privilege Changes Take Effect”. The server bases
access-control decisions on the in-memory copies of the grant
tables.
一些 MySQL 版本在授权表中引入了更改,以添加新的权限或功能。为了确保您能够利用任何新功能,每当升级 MySQL 时,请将您的授权表更新到当前结构。请参阅 第 3 章,升级 MySQL。Some MySQL releases introduce changes to the grant tables to add new privileges or features. To make sure that you can take advantage of any new capabilities, update your grant tables to the current structure whenever you upgrade MySQL. See Chapter 3, Upgrading MySQL.
以下各节概述了可用的权限,提供了每个权限的更详细描述,并提供了使用指南。The following sections summarize the available privileges, provide more detailed descriptions of each privilege, and offer usage guidelines.
下表显示了在GRANT和REVOKE语句中使用的静态权限名称,以及与每个权限相关的授权表中的列名和该权限适用的上下文。The following table shows the static privilege names used in
GRANT and
REVOKE statements, along with the
column name associated with each privilege in the grant tables
and the context in which the privilege applies.
表 8.2 GRANT 和 REVOKE 允许的静态权限Table 8.2 Permissible Static Privileges for GRANT and REVOKE
| 权限Privilege | 授予表列Grant Table Column | 上下文Context |
|---|---|---|
ALL [PRIVILEGES]ALL [PRIVILEGES] |
同义词为“所有权限”Synonym for “all privileges” | 服务器管理Server administration |
ALTERALTER |
Alter_priv |
表格Tables |
ALTER ROUTINE |
Alter_routine_priv |
存储过程Stored routines |
CREATECREATE |
Create_privCreate_priv |
数据库、表或索引Databases, tables, or indexes |
CREATE ROLECREATE ROLE |
Create_role_privCreate_role_priv |
服务器管理Server administration |
CREATE ROUTINECREATE ROUTINE |
Create_routine_privCreate_routine_priv |
存储过程Stored routines |
CREATE TABLESPACECREATE TABLESPACE |
Create_tablespace_privCreate_tablespace_priv |
服务器管理Server administration |
CREATE TEMPORARY TABLESCREATE TEMPORARY TABLES |
Create_tmp_table_privCreate_tmp_table_priv |
表格Tables |
CREATE USERCREATE USER |
Create_user_privCreate_user_priv |
服务器管理Server administration |
CREATE VIEWCREATE VIEW |
Create_view_priv |
浏览量Views |
DELETEDELETE |
Delete_priv |
表格Tables |
DROPDROP |
Drop_priv |
数据库、表或视图Databases, tables, or views |
DROP ROLEDROP ROLE |
Drop_role_privDrop_role_priv |
服务器管理Server administration |
EVENTEVENT |
Event_privEvent_priv |
数据库Databases |
EXECUTEEXECUTE |
Execute_privExecute_priv |
存储过程Stored routines |
FILEFILE |
File_privFile_priv |
服务器主机上的文件访问File access on server host |
GRANT OPTIONGRANT OPTION |
Grant_privGrant_priv |
数据库、表或存储过程Databases, tables, or stored routines |
INDEXINDEX |
Index_priv |
表格Tables |
INSERTINSERT |
Insert_priv |
表格或列Tables or columns |
LOCK TABLESLOCK TABLES |
Lock_tables_priv |
数据库Databases |
PROCESSPROCESS |
Process_priv |
服务器管理Server administration |
PROXYPROXY |
参见 proxies_priv 表See proxies_priv table |
服务器管理Server administration |
REFERENCESREFERENCES |
References_priv |
数据库或表格Databases or tables |
RELOAD |
Reload_priv |
服务器管理Server administration |
REPLICATION CLIENT |
Repl_client_priv |
服务器管理Server administration |
REPLICATION SLAVEREPLICATION SLAVE |
Repl_slave_priv |
服务器管理Server administration |
SELECTSELECT |
Select_priv |
表格或列Tables or columns |
SHOW DATABASESSHOW DATABASES |
Show_db_priv |
服务器管理Server administration |
SHOW VIEWSHOW VIEW |
Show_view_privShow_view_priv |
浏览量Views |
SHUTDOWNSHUTDOWN |
Shutdown_privShutdown_priv |
服务器管理Server administration |
SUPERSUPER |
Super_privSuper_priv |
服务器管理Server administration |
TRIGGERTRIGGER |
Trigger_privTrigger_priv |
表格Tables |
UPDATEUPDATE |
Update_privUpdate_priv |
表格或列Tables or columns |
USAGEUSAGE |
同义词为“无权限”Synonym for “no privileges” | 服务器管理Server administration |
下表显示了在GRANT和REVOKE语句中使用的动态权限名称,以及权限适用的上下文。The following table shows the dynamic privilege names used in
GRANT and
REVOKE statements, along with the
context in which the privilege applies.
表 8.3 GRANT 和 REVOKE 的允许动态权限Table 8.3 Permissible Dynamic Privileges for GRANT and REVOKE
| 权限Privilege | 上下文Context |
|---|---|
ALLOW_NONEXISTENT_DEFINER |
孤立对象保护Orphan object protection |
APPLICATION_PASSWORD_ADMIN |
双重密码管理Dual password administration |
AUDIT_ABORT_EXEMPTAUDIT_ABORT_EXEMPT |
允许被审计日志过滤器阻止的查询Allow queries blocked by audit log filter |
AUDIT_ADMINAUDIT_ADMIN |
审计日志管理Audit log administration |
AUTHENTICATION_POLICY_ADMIN |
认证管理Authentication administration |
BACKUP_ADMINBACKUP_ADMIN |
备份管理Backup administration |
BINLOG_ADMINBINLOG_ADMIN |
备份与复制管理Backup and Replication administration |
BINLOG_ENCRYPTION_ADMINBINLOG_ENCRYPTION_ADMIN |
备份与复制管理Backup and Replication administration |
CLONE_ADMINCLONE_ADMIN |
克隆管理Clone administration |
CONNECTION_ADMINCONNECTION_ADMIN |
服务器管理Server administration |
ENCRYPTION_KEY_ADMINENCRYPTION_KEY_ADMIN |
服务器管理Server administration |
FIREWALL_ADMINFIREWALL_ADMIN |
防火墙管理Firewall administration |
FIREWALL_EXEMPTFIREWALL_EXEMPT |
防火墙管理Firewall administration |
FIREWALL_USERFIREWALL_USER |
防火墙管理Firewall administration |
FLUSH_OPTIMIZER_COSTSFLUSH_OPTIMIZER_COSTS |
服务器管理Server administration |
FLUSH_PRIVILEGESFLUSH_PRIVILEGES |
服务器管理Server administration |
FLUSH_STATUSFLUSH_STATUS |
服务器管理Server administration |
FLUSH_TABLESFLUSH_TABLES |
服务器管理Server administration |
FLUSH_USER_RESOURCESFLUSH_USER_RESOURCES |
服务器管理Server administration |
GROUP_REPLICATION_ADMIN |
复制管理Replication administration |
GROUP_REPLICATION_STREAM |
复制管理Replication administration |
INNODB_REDO_LOG_ARCHIVE |
重做日志归档管理Redo log archiving administration |
INNODB_REDO_LOG_ENABLE |
重做日志管理Redo log administration |
MASKING_DICTIONARIES_ADMIN |
服务器管理Server administration |
NDB_STORED_USER |
NDB 集群NDB Cluster |
OPTIMIZE_LOCAL_TABLE |
OPTIMIZE LOCAL
TABLE 语句OPTIMIZE LOCAL
TABLE statements |
PASSWORDLESS_USER_ADMIN |
认证管理Authentication administration |
PERSIST_RO_VARIABLES_ADMIN |
服务器管理Server administration |
REPLICATION_APPLIER |
PRIVILEGE_CHECKS_USER 用于复制通道PRIVILEGE_CHECKS_USER for a replication channel |
REPLICATION_SLAVE_ADMIN |
复制管理Replication administration |
RESOURCE_GROUP_ADMINRESOURCE_GROUP_ADMIN |
资源组管理Resource group administration |
RESOURCE_GROUP_USER |
资源组管理Resource group administration |
ROLE_ADMIN |
服务器管理Server administration |
SENSITIVE_VARIABLES_OBSERVER |
服务器管理Server administration |
SESSION_VARIABLES_ADMIN |
服务器管理Server administration |
SET_ANY_DEFINER |
服务器管理Server administration |
SHOW_ROUTINE |
服务器管理Server administration |
SKIP_QUERY_REWRITE |
服务器管理Server administration |
SYSTEM_USERSYSTEM_USER |
服务器管理Server administration |
SYSTEM_VARIABLES_ADMINSYSTEM_VARIABLES_ADMIN |
服务器管理Server administration |
TABLE_ENCRYPTION_ADMINTABLE_ENCRYPTION_ADMIN |
服务器管理Server administration |
TELEMETRY_LOG_ADMINTELEMETRY_LOG_ADMIN |
在 AWS 上管理 MySQL HeatWave 的遥测日志Telemetry log administration for MySQL HeatWave on AWS |
TP_CONNECTION_ADMIN |
线程池管理Thread pool administration |
TRANSACTION_GTID_TAG |
复制管理Replication administration |
VERSION_TOKEN_ADMIN |
服务器管理Server administration |
XA_RECOVER_ADMIN |
服务器管理Server administration |
静态权限是内置在服务器中的,与动态权限形成对比,动态权限是在运行时定义的。以下列表描述了 MySQL 中可用的每个静态权限。Static privileges are built in to the server, in contrast to dynamic privileges, which are defined at runtime. The following list describes each static privilege available in MySQL.
某些特定的 SQL 语句可能有比此处所示更具体的权限要求。如果是这样,相关语句的描述将提供详细信息。Particular SQL statements might have more specific privilege requirements than indicated here. If so, the description for the statement in question provides the details.
ALL,ALL PRIVILEGESALL,ALL PRIVILEGES这些权限说明符是“在给定权限级别下可用的所有权限”的简写(除了
GRANT OPTION)。例如,在全局或表级授予ALL,分别授予所有全局权限或所有表级权限。These privilege specifiers are shorthand for “all privileges available at a given privilege level” (exceptGRANT OPTION). For example, grantingALLat the global or table level grants all global privileges or all table-level privileges, respectively.启用使用
ALTER TABLE语句来更改表的结构。ALTER TABLE也需要CREATE和INSERT权限。重命名表需要在旧表上具有ALTER和DROP权限,在新表上具有CREATE和INSERT权限。Enables use of theALTER TABLEstatement to change the structure of tables.ALTER TABLEalso requires theCREATEandINSERTprivileges. Renaming a table requiresALTERandDROPon the old table,CREATE, andINSERTon the new table.允许使用修改或删除存储例程(存储过程和函数)的语句。对于在授予权限的范围内的例程,并且用户不是被指定为例程
DEFINER的用户,还允许访问例程定义之外的例程属性。Enables use of statements that alter or drop stored routines (stored procedures and functions). For routines that fall within the scope at which the privilege is granted and for which the user is not the user named as the routineDEFINER, also enables access to routine properties other than the routine definition.启用使用创建新数据库和表的语句。Enables use of statements that create new databases and tables.
允许使用
CREATE ROLE语句。(CREATE ROLE权限也允许使用CREATE USER语句。)参见 第 8.2.10 节,“使用角色”。Enables use of theCREATE ROLEstatement. (TheCREATE USERprivilege also enables use of theCREATE ROLEstatement.) See Section 8.2.10, “Using Roles”.CREATE ROLE和DROP ROLE权限没有CREATE USER权限强大,因为它们只能用于创建和删除账户。它们不能像CREATE USER那样修改账户属性或重命名账户。参见 用户和角色的可互换性。TheCREATE ROLEandDROP ROLEprivileges are not as powerful asCREATE USERbecause they can be used only to create and drop accounts. They cannot be used asCREATE USERcan be modify account attributes or rename accounts. See User and Role Interchangeability.允许使用创建存储例程(存储过程和函数)的语句。对于在授予权限范围内的例程,并且用户不是指定为例程
DEFINER的用户,也允许访问除例程定义之外的例程属性。Enables use of statements that create stored routines (stored procedures and functions). For routines that fall within the scope at which the privilege is granted and for which the user is not the user named as the routineDEFINER, also enables access to routine properties other than the routine definition.CREATE TABLESPACECREATE TABLESPACE允许使用创建、修改或删除表空间和日志文件组的语句。Enables use of statements that create, alter, or drop tablespaces and log file groups.
CREATE TEMPORARY TABLESCREATE TEMPORARY TABLES允许使用
CREATE TEMPORARY TABLE语句创建临时表。Enables the creation of temporary tables using theCREATE TEMPORARY TABLEstatement.在会话创建临时表之后,服务器不会对该表进行进一步的权限检查。创建会话可以对该表执行任何操作,例如
DROP TABLE、INSERT、UPDATE或SELECT。欲了解更多信息,请参见 第 15.1.20.2 节,“CREATE TEMPORARY TABLE 语句”。After a session has created a temporary table, the server performs no further privilege checks on the table. The creating session can perform any operation on the table, such asDROP TABLE,INSERT,UPDATE, orSELECT. For more information, see Section 15.1.20.2, “CREATE TEMPORARY TABLE Statement”.启用使用
ALTER USER、CREATE ROLE、CREATE USER、DROP ROLE、DROP USER、RENAME USER和REVOKE ALL PRIVILEGES语句。Enables use of theALTER USER,CREATE ROLE,CREATE USER,DROP ROLE,DROP USER,RENAME USER, andREVOKE ALL PRIVILEGESstatements.允许使用
CREATE VIEW语句。Enables use of theCREATE VIEWstatement.允许从数据库中的表删除行。Enables rows to be deleted from tables in a database.
允许使用删除(移除)现有数据库、表和视图的语句。使用分区表上的
ALTER TABLE ... DROP PARTITION语句需要DROP权限。使用TRUNCATE TABLE语句也需要DROP权限。Enables use of statements that drop (remove) existing databases, tables, and views. TheDROPprivilege is required to use theALTER TABLE ... DROP PARTITIONstatement on a partitioned table. TheDROPprivilege is also required forTRUNCATE TABLE.启用使用
DROP ROLE语句。(CREATE USER权限也能启用使用DROP ROLE语句。)请参阅 第 8.2.10 节,“使用角色”。Enables use of theDROP ROLEstatement. (TheCREATE USERprivilege also enables use of theDROP ROLEstatement.) See Section 8.2.10, “Using Roles”.CREATE ROLE和DROP ROLE权限没有CREATE USER权限强大,因为它们只能用于创建和删除账户。它们不能像CREATE USER那样修改账户属性或重命名账户。参见 用户和角色的可互换性。TheCREATE ROLEandDROP ROLEprivileges are not as powerful asCREATE USERbecause they can be used only to create and drop accounts. They cannot be used asCREATE USERcan be modify account attributes or rename accounts. See User and Role Interchangeability.启用使用用于事件调度程序的创建、修改、删除或显示事件的语句。Enables use of statements that create, alter, drop, or display events for the Event Scheduler.
启用使用执行存储程序(存储过程和函数)的语句。对于在授予权限的范围内且用户不是指定为程序
DEFINER的用户的程序,还可以访问除程序定义以外的程序属性。Enables use of statements that execute stored routines (stored procedures and functions). For routines that fall within the scope at which the privilege is granted and for which the user is not the user named as the routineDEFINER, also enables access to routine properties other than the routine definition.影响以下操作和服务器行为:Affects the following operations and server behaviors:
启用使用
LOAD DATA和SELECT ... INTO OUTFILE语句以及LOAD_FILE()函数在服务器主机上读写文件。拥有FILE权限的用户可以读取服务器主机上任何对所有人可读或对 MySQL 服务器可读的文件。(这意味着用户可以读取任何数据库目录中的任何文件,因为服务器可以访问这些文件中的任何一个。)Enables reading and writing files on the server host using theLOAD DATAandSELECT ... INTO OUTFILEstatements and theLOAD_FILE()function. A user who has theFILEprivilege can read any file on the server host that is either world-readable or readable by the MySQL server. (This implies the user can read any file in any database directory, because the server can access any of those files.)允许在 MySQL 服务器具有写入权限的任何目录中创建新文件。这包括包含实现权限表的文件的服务器数据目录。Enables creating new files in any directory where the MySQL server has write access. This includes the server's data directory containing the files that implement the privilege tables.
启用在
CREATE TABLE语句中使用DATA DIRECTORY或INDEX DIRECTORY表选项。Enables use of theDATA DIRECTORYorINDEX DIRECTORYtable option for theCREATE TABLEstatement.
出于安全考虑,服务器不会覆盖现有文件。As a security measure, the server does not overwrite existing files.
要限制文件读取和写入的位置,请将
secure_file_priv系统变量设置为特定目录。参见 第 7.1.8 节,“服务器系统变量”。To limit the location in which files can be read and written, set thesecure_file_privsystem variable to a specific directory. See Section 7.1.8, “Server System Variables”.允许您向其他用户授予或撤销您自己拥有的权限。Enables you to grant to or revoke from other users those privileges that you yourself possess.
允许使用创建或删除(移除)索引的语句。
INDEX适用于现有表。如果你拥有表的CREATE权限,你可以在CREATE TABLE语句中包含索引定义。Enables use of statements that create or drop (remove) indexes.INDEXapplies to existing tables. If you have theCREATEprivilege for a table, you can include index definitions in theCREATE TABLEstatement.允许向数据库中的表插入行。
INSERT也需要用于ANALYZE TABLE、OPTIMIZE TABLE和REPAIR TABLE表维护语句。Enables rows to be inserted into tables in a database.INSERTis also required for theANALYZE TABLE,OPTIMIZE TABLE, andREPAIR TABLEtable-maintenance statements.允许使用显式的
LOCK TABLES语句锁定你拥有SELECT权限的表。这包括使用写锁,这会阻止其他会话读取被锁定的表。Enables use of explicitLOCK TABLESstatements to lock tables for which you have theSELECTprivilege. This includes use of write locks, which prevents other sessions from reading the locked table.PROCESS权限控制对服务器中正在执行的线程信息的访问(即会话正在执行的语句的信息)。可通过以下方式访问线程信息:使用SHOW PROCESSLIST语句、mysqladmin processlist 命令、信息模式PROCESSLIST表以及性能模式processlist表,如下所示:ThePROCESSprivilege controls access to information about threads executing within the server (that is, information about statements being executed by sessions). Thread information available using theSHOW PROCESSLISTstatement, the mysqladmin processlist command, the Information SchemaPROCESSLISTtable, and the Performance Schemaprocesslisttable is accessible as follows:拥有
PROCESS权限的用户可以访问所有线程的信息,即使是属于其他用户的线程。With thePROCESSprivilege, a user has access to information about all threads, even those belonging to other users.没有
PROCESS权限的非匿名用户只能访问他们自己的线程信息,而无法访问其他用户的线程信息,匿名用户则无法访问任何线程信息。Without thePROCESSprivilege, nonanonymous users have access to information about their own threads but not threads for other users, and anonymous users have no access to thread information.
NotePerformance Schema 的
threads表也提供线程信息,但表访问使用的是不同的权限模型。参见第 29.12.22.8 节,“threads 表”。The Performance Schemathreadstable also provides thread information, but table access uses a different privilege model. See Section 29.12.22.8, “The threads Table”.PROCESS权限还允许使用SHOW ENGINE语句,访问INFORMATION_SCHEMA的InnoDB表(表名以INNODB_开头),以及访问INFORMATION_SCHEMA的FILES表。ThePROCESSprivilege also enables use of theSHOW ENGINEstatement, access to theINFORMATION_SCHEMAInnoDBtables (tables with names that begin withINNODB_), and access to theINFORMATION_SCHEMAFILEStable.允许一个用户冒充或被识别为另一个用户。参见 第 8.2.19 节,“代理用户”。Enables one user to impersonate or become known as another user. See Section 8.2.19, “Proxy Users”.
创建外键约束需要对父表具有
REFERENCES权限。Creation of a foreign key constraint requires theREFERENCESprivilege for the parent table.RELOAD权限允许以下操作:TheRELOADenables the following operations:使用与
FLUSH操作等效的 mysqladmin 命令:flush-hosts、flush-logs、flush-privileges、flush-status、flush-tables、refresh和reload。Use of mysqladmin commands that are equivalent toFLUSHoperations:flush-hosts,flush-logs,flush-privileges,flush-status,flush-tables,refresh, andreload.reload命令告诉服务器将授权表重新加载到内存中。flush-privileges是reload的同义词。refresh命令关闭并重新打开日志文件,并刷新所有表。其他flush-命令执行与xxxrefresh类似的功能,但更具体,在某些情况下可能更可取。例如,如果你只想刷新日志文件,flush-logs比refresh更合适。Thereloadcommand tells the server to reload the grant tables into memory.flush-privilegesis a synonym forreload. Therefreshcommand closes and reopens the log files and flushes all tables. The otherflush-commands perform functions similar toxxxrefresh, but are more specific and may be preferable in some instances. For example, if you want to flush just the log files,flush-logsis a better choice thanrefresh.使用 mysqldump 选项执行各种
FLUSH操作:--flush-logs和--source-data。Use of mysqldump options that perform variousFLUSHoperations:--flush-logsand--source-data.使用
RESET BINARY LOGS AND GTIDS和RESET REPLICA语句。Use of theRESET BINARY LOGS AND GTIDSandRESET REPLICAstatements.
REPLICATION CLIENTREPLICATION CLIENT允许使用
SHOW BINARY LOG STATUS、SHOW REPLICA STATUS和SHOW BINARY LOGS语句。Enables use of theSHOW BINARY LOG STATUS,SHOW REPLICA STATUS, andSHOW BINARY LOGSstatements.REPLICATION SLAVEREPLICATION SLAVE允许账户请求已在复制源服务器的数据库上进行的更新,使用
SHOW REPLICAS、SHOW RELAYLOG EVENTS和SHOW BINLOG EVENTS语句。使用 mysqlbinlog 选项--read-from-remote-server(-R) 和--read-from-remote-source也需要此权限。将此权限授予用于副本连接当前服务器作为其复制源服务器的账户。Enables the account to request updates that have been made to databases on the replication source server, using theSHOW REPLICAS,SHOW RELAYLOG EVENTS, andSHOW BINLOG EVENTSstatements. This privilege is also required to use the mysqlbinlog options--read-from-remote-server(-R) and--read-from-remote-source. Grant this privilege to accounts that are used by replicas to connect to the current server as their replication source server.允许从数据库中的表中选择行。
SELECT语句只有在实际访问表时才需要SELECT权限。有些SELECT语句不访问表,可以在没有任何数据库权限的情况下执行。例如,你可以使用SELECT作为简单计算器来计算与表无关的表达式:Enables rows to be selected from tables in a database.SELECTstatements require theSELECTprivilege only if they actually access tables. SomeSELECTstatements do not access tables and can be executed without permission for any database. For example, you can useSELECTas a simple calculator to evaluate expressions that make no reference to tables:SELECT 1+1; SELECT PI()*2;
还需要
SELECT权限来执行读取列值的其他语句。例如,在UPDATE语句中,SELECT权限是必须的,用于col_name=expr赋值右侧引用的列,或用于DELETE或UPDATE语句WHERE子句中指定的列。TheSELECTprivilege is also needed for other statements that read column values. For example,SELECTis needed for columns referenced on the right hand side ofcol_name=exprassignment inUPDATEstatements or for columns named in theWHEREclause ofDELETEorUPDATEstatements.使用
SELECT权限是对用在EXPLAIN的表或视图所必需的,包括视图定义中任何基础表。TheSELECTprivilege is needed for tables or views used withEXPLAIN, including any underlying tables in view definitions.允许账户通过执行
SHOW DATABASE语句查看数据库名称。没有此权限的账户只能看到自己拥有某些权限的数据库,并且如果服务器是使用--skip-show-database选项启动的,则完全无法使用该语句。Enables the account to see database names by issuing theSHOW DATABASEstatement. Accounts that do not have this privilege see only databases for which they have some privileges, and cannot use the statement at all if the server was started with the--skip-show-databaseoption.Caution因为任何静态全局权限都被视为对所有数据库的权限,所以任何静态全局权限都可以使用户通过
SHOW DATABASES查看所有数据库名称,或通过检查SCHEMATA表(位于INFORMATION_SCHEMA中)来查看所有数据库名称,但被数据库级别的部分撤销限制的数据库除外。Because any static global privilege is considered a privilege for all databases, any static global privilege enables a user to see all database names withSHOW DATABASESor by examining theSCHEMATAtable ofINFORMATION_SCHEMA, except databases that have been restricted at the database level by partial revokes.启用使用
SHOW CREATE VIEW语句。此权限对于与EXPLAIN一起使用的视图也是必需的。Enables use of theSHOW CREATE VIEWstatement. This privilege is also needed for views used withEXPLAIN.启用使用
SHUTDOWN和RESTART语句,mysqladmin shutdown命令,以及mysql_shutdown()C API 函数。Enables use of theSHUTDOWNandRESTARTstatements, the mysqladmin shutdown command, and themysql_shutdown()C API function.SUPER是一个强大且影响深远的权限,不应轻易授予。如果一个账户只需要执行SUPER操作的子集,可以通过授予一个或多个动态权限来实现所需的权限集,每个动态权限都赋予更有限的能力。请参见 动态权限描述。SUPERis a powerful and far-reaching privilege and should not be granted lightly. If an account needs to perform only a subset ofSUPERoperations, it may be possible to achieve the desired privilege set by instead granting one or more dynamic privileges, each of which confers more limited capabilities. See Dynamic Privilege Descriptions.NoteSUPER已被弃用,您应预计它将在 MySQL 的未来版本中被移除。请参阅 将账户从 SUPER 迁移到动态权限。SUPERis deprecated, and you should expect it to be removed in a future version of MySQL. See Migrating Accounts from SUPER to Dynamic Privileges.SUPER影响以下操作和服务器行为:SUPERaffects the following operations and server behaviors:在运行时启用系统变量更改:Enables system variable changes at runtime:
允许使用
SET GLOBAL和SET PERSIST对全局系统变量进行服务器配置更改。Enables server configuration changes to global system variables withSET GLOBALandSET PERSIST.相应的动态权限是
SYSTEM_VARIABLES_ADMIN。The corresponding dynamic privilege isSYSTEM_VARIABLES_ADMIN.启用设置需要特殊权限的受限会话系统变量。Enables setting restricted session system variables that require a special privilege.
对应的动态权限是
SESSION_VARIABLES_ADMIN。The corresponding dynamic privilege isSESSION_VARIABLES_ADMIN.
另请参见 第 7.1.9.1 节,“系统变量权限”。See also Section 7.1.9.1, “System Variable Privileges”.
允许更改全局事务特性(参见 第 15.3.7 节,“SET TRANSACTION 语句”)。Enables changes to global transaction characteristics (see Section 15.3.7, “SET TRANSACTION Statement”).
相应的动态权限是
SYSTEM_VARIABLES_ADMIN。The corresponding dynamic privilege isSYSTEM_VARIABLES_ADMIN.允许该账户启动和停止复制,包括组复制。Enables the account to start and stop replication, including Group Replication.
相应的动态权限是普通复制的
REPLICATION_SLAVE_ADMIN,组复制的GROUP_REPLICATION_ADMIN。The corresponding dynamic privilege isREPLICATION_SLAVE_ADMINfor regular replication,GROUP_REPLICATION_ADMINfor Group Replication.允许使用
CHANGE REPLICATION SOURCE TO和CHANGE REPLICATION FILTER语句。Enables use ofCHANGE REPLICATION SOURCE TOandCHANGE REPLICATION FILTERstatements.相应的动态权限是
REPLICATION_SLAVE_ADMIN。The corresponding dynamic privilege isREPLICATION_SLAVE_ADMIN.通过
PURGE BINARY LOGS和BINLOG语句启用二进制日志控制。Enables binary log control by means of thePURGE BINARY LOGSandBINLOGstatements.相应的动态权限是
BINLOG_ADMIN。The corresponding dynamic privilege isBINLOG_ADMIN.启用在执行视图或存储程序时设置有效授权 ID。拥有此权限的用户可以在视图或存储程序的
DEFINER属性中指定任何帐户。Enables setting the effective authorization ID when executing a view or stored program. A user with this privilege can specify any account in theDEFINERattribute of a view or stored program.相应的动态权限是
SET_ANY_DEFINER和ALLOW_NONEXISTENT_DEFINER。The corresponding dynamic privileges areSET_ANY_DEFINERandALLOW_NONEXISTENT_DEFINER.允许使用
CREATE SERVER、ALTER SERVER和DROP SERVER语句。Enables use of theCREATE SERVER,ALTER SERVER, andDROP SERVERstatements.允许使用 mysqladmin debug 命令。Enables use of the mysqladmin debug command.
启用
InnoDB加密密钥轮换。EnablesInnoDBencryption key rotation.相应的动态权限是
ENCRYPTION_KEY_ADMIN。The corresponding dynamic privilege isENCRYPTION_KEY_ADMIN.启用执行版本令牌函数。Enables execution of Version Tokens functions.
相应的动态权限是
VERSION_TOKEN_ADMIN。The corresponding dynamic privilege isVERSION_TOKEN_ADMIN.启用授予和撤销角色、使用
GRANT语句的WITH ADMIN OPTION子句,并在ROLES_GRAPHML()函数结果中使用非空的<graphml>元素内容。Enables granting and revoking roles, use of theWITH ADMIN OPTIONclause of theGRANTstatement, and nonempty<graphml>element content in the result from theROLES_GRAPHML()function.相应的动态权限是
ROLE_ADMIN。The corresponding dynamic privilege isROLE_ADMIN.允许控制不允许非
SUPER账户访问的客户端连接:Enables control over client connections not permitted to non-SUPERaccounts:启用使用
KILL语句或 mysqladmin kill 命令终止属于其他账户的线程。(账户总是可以终止自己的线程。)Enables use of theKILLstatement or mysqladmin kill command to kill threads belonging to other accounts. (An account can always kill its own threads.)当
SUPER客户端连接时,服务器不会执行init_connect系统变量的内容。The server does not executeinit_connectsystem variable content whenSUPERclients connect.即使已达到由
max_connections系统变量配置的连接限制,服务器仍接受来自SUPER客户端的一个连接。The server accepts one connection from aSUPERclient even if the connection limit configured by themax_connectionssystem variable is reached.处于离线模式的服务器(
offline_mode启用)不会在下一个客户端请求时终止SUPER客户端连接,并接受来自SUPER客户端的新连接。A server in offline mode (offline_modeenabled) does not terminateSUPERclient connections at the next client request, and accepts new connections fromSUPERclients.即使启用了
read_only系统变量,也可以执行更新操作。这适用于显式的表更新,以及使用诸如GRANT和REVOKE的帐户管理语句,这些语句会隐式更新表。Updates can be performed even when theread_onlysystem variable is enabled. This applies to explicit table updates, and to use of account-management statements such asGRANTandREVOKEthat update tables implicitly.
前述连接控制操作对应的动态权限是
CONNECTION_ADMIN。The corresponding dynamic privilege for the preceding connection control operations isCONNECTION_ADMIN.
如果启用了二进制日志,您可能还需要
SUPER权限来创建或修改存储函数,如 第 27.7 节,“存储程序二进制日志” 所述。You may also need theSUPERprivilege to create or alter stored functions if binary logging is enabled, as described in Section 27.7, “Stored Program Binary Logging”.启用触发器操作。您必须拥有此表的此权限才能创建、删除、执行或显示该表的触发器。Enables trigger operations. You must have this privilege for a table to create, drop, execute, or display triggers for that table.
当触发器被触发(由有权限执行与触发器相关的表的
INSERT、UPDATE或DELETE语句的用户触发)、执行触发器需要定义该触发器的用户仍然拥有该表的TRIGGER权限。When a trigger is activated (by a user who has privileges to executeINSERT,UPDATE, orDELETEstatements for the table associated with the trigger), trigger execution requires that the user who defined the trigger still have theTRIGGERprivilege for the table.使表中的行可以在数据库中更新。Enables rows to be updated in tables in a database.
该权限指定符表示 “无权限。” 它在全局级别与
GRANT一起使用,以在权限列表中未指定具体账户权限的情况下指定诸如WITH GRANT OPTION的子句。SHOW GRANTS会显示USAGE,以表示某个账户在某个权限级别上没有权限。This privilege specifier stands for “no privileges.” It is used at the global level withGRANTto specify clauses such asWITH GRANT OPTIONwithout naming specific account privileges in the privilege list.SHOW GRANTSdisplaysUSAGEto indicate that an account has no privileges at a privilege level.
动态权限是在运行时定义的,与静态权限形成对比,静态权限是内置在服务器中的。以下列表描述了 MySQL 中可用的每个动态权限。Dynamic privileges are defined at runtime, in contrast to static privileges, which are built in to the server. The following list describes each dynamic privilege available in MySQL.
大多数动态权限在服务器启动时定义。其他权限则由特定组件或插件定义,如权限描述中所示。在这种情况下,除非启用了定义该权限的组件或插件,否则该权限不可用。Most dynamic privileges are defined at server startup. Others are defined by a particular component or plugin, as indicated in the privilege descriptions. In such cases, the privilege is unavailable unless the component or plugin that defines it is enabled.
某些特定的 SQL 语句可能有比此处所示更具体的权限要求。如果是这样,相关语句的描述将提供详细信息。Particular SQL statements might have more specific privilege requirements than indicated here. If so, the description for the statement in question provides the details.
ALLOW_NONEXISTENT_DEFINERALLOW_NONEXISTENT_DEFINER启用覆盖安全检查,这些检查旨在防止操作(可能无意中)导致存储对象成为孤立,或导致采用当前孤立的存储对象。没有此权限,任何试图生成孤立 SQL 存储过程、函数或视图的操作都会导致错误。试图使用
CREATE PROCEDURE、CREATE FUNCTION、CREATE TRIGGER、CREATE EVENT或CREATE VIEW生成孤立对象的操作,除了需要ALLOW_NONEXISTENT_DEFINER外,还需要SET_ANY_DEFINER,以允许定义者与当前用户不同。Enables overriding security checks designed to prevent operations that (perhaps inadvertently) cause stored objects to become orphaned or that cause adoption of stored objects that are currently orphaned. Without this privilege, any attempt to produce an orphaned SQL procedure, function, or view results in an error. An attempt to produce orphaned objects usingCREATE PROCEDURE,CREATE FUNCTION,CREATE TRIGGER,CREATE EVENT, orCREATE VIEWalso requiresSET_ANY_DEFINERin addition toALLOW_NONEXISTENT_DEFINER, so that a definer different from the current user is permissible.有关详细信息,请参见 孤立存储对象。For details, see Orphan Stored Objects.
对于双密码功能,此权限允许在
ALTER USER和SET PASSWORD语句中使用RETAIN CURRENT PASSWORD和DISCARD OLD PASSWORD子句,这些语句适用于您自己的账户。管理您自己的次要密码需要此权限,因为大多数用户只需要一个密码。For dual-password capability, this privilege enables use of theRETAIN CURRENT PASSWORDandDISCARD OLD PASSWORDclauses forALTER USERandSET PASSWORDstatements that apply to your own account. This privilege is required to manipulate your own secondary password because most users require only one password.如果一个账户被允许操作所有账户的次要密码,它应该被授予
CREATE USER权限,而不是APPLICATION_PASSWORD_ADMIN权限。If an account is to be permitted to manipulate secondary passwords for all accounts, it should be granted theCREATE USERprivilege rather thanAPPLICATION_PASSWORD_ADMIN.有关使用双重密码的更多信息,请参见第 8.2.15 节,“密码管理”。For more information about use of dual passwords, see Section 8.2.15, “Password Management”.
允许被审计日志过滤器中的 “abort” 项阻止的查询。此权限由
audit_log插件定义;参见 第 8.4.5 节,“MySQL 企业审计”。Allows queries blocked by an “abort” item in the audit log filter. This privilege is defined by theaudit_logplugin; see Section 8.4.5, “MySQL Enterprise Audit”.具有
SYSTEM_USER权限创建的帐户在创建时会自动分配AUDIT_ABORT_EXEMPT权限。在进行升级过程时,如果现有帐户中没有分配该权限,则SYSTEM_USER权限的现有帐户也会被分配AUDIT_ABORT_EXEMPT权限。因此,具有SYSTEM_USER权限的帐户可以在审计配置错误后用于恢复系统访问权限。Accounts created with theSYSTEM_USERprivilege have theAUDIT_ABORT_EXEMPTprivilege assigned automatically when they are created. TheAUDIT_ABORT_EXEMPTprivilege is also assigned to existing accounts with theSYSTEM_USERprivilege when you carry out an upgrade procedure, if no existing accounts have that privilege assigned. Accounts with theSYSTEM_USERprivilege can therefore be used to regain access to a system following an audit misconfiguration.启用审计日志配置。此权限由
audit_log插件定义;请参阅 第 8.4.5 节,“MySQL 企业审计”。Enables audit log configuration. This privilege is defined by theaudit_logplugin; see Section 8.4.5, “MySQL Enterprise Audit”.启用执行
LOCK INSTANCE FOR BACKUP语句,并访问性能模式的log_status表。Enables execution of theLOCK INSTANCE FOR BACKUPstatement and access to the Performance Schemalog_statustable.Note除了
BACKUP_ADMIN外,要访问它,还需要在log_status表上具有SELECT权限。BesidesBACKUP_ADMIN, theSELECTprivilege on thelog_statustable is also needed for its access.在从早期版本就地升级到 MySQL 8.4 时,拥有
RELOAD权限的用户会自动获得BACKUP_ADMIN权限。TheBACKUP_ADMINprivilege is automatically granted to users with theRELOADprivilege when performing an in-place upgrade to MySQL 8.4 from an earlier version.AUTHENTICATION_POLICY_ADMINAUTHENTICATION_POLICY_ADMINauthentication_policy系统变量对CREATE USER和ALTER USER语句中与认证相关的子句的使用施加了某些限制。拥有AUTHENTICATION_POLICY_ADMIN权限的用户不受这些限制约束。(对于原本不被允许的语句,会出现警告。)Theauthentication_policysystem variable places certain constraints on how the authentication-related clauses ofCREATE USERandALTER USERstatements may be used. A user who has theAUTHENTICATION_POLICY_ADMINprivilege is not subject to these constraints. (A warning does occur for statements that otherwise would not be permitted.)有关
authentication_policy施加的限制的详细信息,请参阅该变量的说明。For details about the constraints imposed byauthentication_policy, see the description of that variable.通过
PURGE BINARY LOGS和BINLOG语句启用二进制日志控制。Enables binary log control by means of thePURGE BINARY LOGSandBINLOGstatements.启用设置系统变量
binlog_encryption,该变量用于激活或停用二进制日志文件和中继日志文件的加密。此功能不由BINLOG_ADMIN、SYSTEM_VARIABLES_ADMIN或SESSION_VARIABLES_ADMIN权限提供。相关系统变量binlog_rotate_encryption_master_key_at_startup,在服务器重启时会自动轮换二进制日志主密钥,不需要此权限。Enables setting the system variablebinlog_encryption, which activates or deactivates encryption for binary log files and relay log files. This ability is not provided by theBINLOG_ADMIN,SYSTEM_VARIABLES_ADMIN, orSESSION_VARIABLES_ADMINprivileges. The related system variablebinlog_rotate_encryption_master_key_at_startup, which rotates the binary log master key automatically when the server is restarted, does not require this privilege.允许执行
CLONE语句。包括BACKUP_ADMIN和SHUTDOWN权限。Enables execution of theCLONEstatements. IncludesBACKUP_ADMINandSHUTDOWNprivileges.启用使用
KILL语句或 mysqladmin kill 命令终止属于其他账户的线程。(账户总是可以终止自己的线程。)Enables use of theKILLstatement or mysqladmin kill command to kill threads belonging to other accounts. (An account can always kill its own threads.)允许设置与客户端连接相关的系统变量,或者规避与客户端连接相关的限制。激活 MySQL 服务器的离线模式需要
CONNECTION_ADMIN权限,这可以通过将offline_mode系统变量的值更改为ON来完成。Enables setting system variables related to client connections, or circumventing restrictions related to client connections.CONNECTION_ADMINis required to activate MySQL Server’s offline mode, which is done by changing the value of theoffline_modesystem variable toON.拥有
CONNECTION_ADMIN权限的管理员可以绕过以下系统变量的影响:TheCONNECTION_ADMINprivilege enables administrators with it to bypass effects of these system variables:init_connect:当CONNECTION_ADMIN客户端连接时,服务器不会执行init_connect系统变量的内容。init_connect: The server does not executeinit_connectsystem variable content whenCONNECTION_ADMINclients connect.max_connections:即使达到max_connections系统变量配置的连接上限,服务器仍允许来自CONNECTION_ADMIN客户端的一个连接。max_connections: The server accepts one connection from aCONNECTION_ADMINclient even if the connection limit configured by themax_connectionssystem variable is reached.offline_mode:处于离线模式的服务器(offline_mode已启用)不会在下一个客户端请求时终止CONNECTION_ADMIN客户端连接,并且会接受来自CONNECTION_ADMIN客户端的新连接。offline_mode: A server in offline mode (offline_modeenabled) does not terminateCONNECTION_ADMINclient connections at the next client request, and accepts new connections fromCONNECTION_ADMINclients.read_only:即使read_only系统变量已启用,来自CONNECTION_ADMIN客户端的更新仍然可以执行。这适用于显式的表更新,以及诸如GRANT和REVOKE等会隐式更新表的账户管理语句。read_only: Updates fromCONNECTION_ADMINclients can be performed even when theread_onlysystem variable is enabled. This applies to explicit table updates, and to account management statements such asGRANTandREVOKEthat update tables implicitly.
Group Replication 组的成员需要
CONNECTION_ADMIN权限,以确保如果参与的某个服务器被置于离线模式,Group Replication 连接不会被终止。如果使用的是 MySQL 通信堆栈(group_replication_communication_stack = MYSQL),没有此权限,被置于离线模式的成员会被从组中驱逐。Group Replication group members need theCONNECTION_ADMINprivilege so that Group Replication connections are not terminated if one of the servers involved is placed in offline mode. If the MySQL communication stack is in use (group_replication_communication_stack = MYSQL), without this privilege, a member that is placed in offline mode is expelled from the group.启用
InnoDB加密密钥轮换。EnablesInnoDBencryption key rotation.允许用户为任何用户管理防火墙规则。此权限由
MYSQL_FIREWALL插件定义;请参阅 第 8.4.7 节,“MySQL 企业防火墙”。Enables a user to administer firewall rules for any user. This privilege is defined by theMYSQL_FIREWALLplugin; see Section 8.4.7, “MySQL Enterprise Firewall”.具有此权限的用户免于防火墙的限制。此权限由
MYSQL_FIREWALL插件定义;请参阅 第 8.4.7 节,“MySQL 企业防火墙”。A user with this privilege is exempt from firewall restrictions. This privilege is defined by theMYSQL_FIREWALLplugin; see Section 8.4.7, “MySQL Enterprise Firewall”.允许用户更新自己的防火墙规则。此权限由
MYSQL_FIREWALL插件定义;请参见 第 8.4.7 节,“MySQL 企业防火墙”。Enables users to update their own firewall rules. This privilege is defined by theMYSQL_FIREWALLplugin; see Section 8.4.7, “MySQL Enterprise Firewall”.允许使用
FLUSH OPTIMIZER_COSTS语句。Enables use of theFLUSH OPTIMIZER_COSTSstatement.允许使用
FLUSH PRIVILEGES语句。Enables use of theFLUSH PRIVILEGESstatement.启用使用
FLUSH STATUS语句。Enables use of theFLUSH STATUSstatement.启用使用
FLUSH TABLES语句。Enables use of theFLUSH TABLESstatement.启用使用
FLUSH USER_RESOURCES语句。Enables use of theFLUSH USER_RESOURCESstatement.允许该账户使用
START GROUP REPLICATION和STOP GROUP REPLICATION语句启动和停止组复制,修改group_replication_consistency系统变量的全局设置,并使用group_replication_set_write_concurrency()和group_replication_set_communication_protocol()函数。将此权限授予用于管理复制组成员服务器的账户。Enables the account to start and stop Group Replication using theSTART GROUP REPLICATIONandSTOP GROUP REPLICATIONstatements, to change the global setting for thegroup_replication_consistencysystem variable, and to use thegroup_replication_set_write_concurrency()andgroup_replication_set_communication_protocol()functions. Grant this privilege to accounts that are used to administer servers that are members of a replication group.允许用户帐户用于建立组复制的组通信连接。当使用 MySQL 通信栈进行组复制时,必须将其授予恢复用户 (
group_replication_communication_stack=MYSQL)。Allows a user account to be used for establishing Group Replication's group communication connections. It must be granted to a recovery user when the MySQL communication stack is used for Group Replication (group_replication_communication_stack=MYSQL).允许账户启用和禁用重做日志归档。Enables the account to activate and deactivate redo log archiving.
启用使用
ALTER INSTANCE {ENABLE|DISABLE} INNODB REDO_LOG语句来启用或禁用重做日志记录。Enables use of theALTER INSTANCE {ENABLE|DISABLE} INNODB REDO_LOGstatement to enable or disable redo logging.参见 禁用重做日志记录。See Disabling Redo Logging.
允许账户使用
masking_dictionary_term_add()和masking_dictionary_term_remove()组件函数添加和移除字典条目。账户还需要此动态权限才能使用masking_dictionary_remove()函数移除整个字典,该函数会删除当前位于mysql.masking_dictionaries表中与指定字典相关的所有条目。Enables the account to add and remove dictionary terms using themasking_dictionary_term_add()andmasking_dictionary_term_remove()component functions. Accounts also require this dynamic privilege to remove a full dictionary using themasking_dictionary_remove()function, which removes all of the terms associated with the named dictionary currently in themysql.masking_dictionariestable.参见 第 8.5 节,“MySQL 企业数据掩码与去标识”。See Section 8.5, “MySQL Enterprise Data Masking and De-Identification”.
使用户或角色及其权限能够在所有支持
NDB的 MySQL 服务器之间共享和同步,只要它们加入指定的 NDB 集群。该权限仅在启用NDB存储引擎时可用。Enables the user or role and its privileges to be shared and synchronized between allNDB-enabled MySQL servers as soon as they join a given NDB Cluster. This privilege is available only if theNDBstorage engine is enabled.对给定用户或角色进行的任何权限更改或撤销都会立即与所有连接的 MySQL 服务器(SQL 节点)同步。您应该注意,不保证来自不同 SQL 节点的影响权限的多个语句在所有 SQL 节点上按相同顺序执行。因此,强烈建议所有用户管理操作都从单个指定的 SQL 节点进行。Any changes to or revocations of privileges made for the given user or role are synchronized immediately with all connected MySQL servers (SQL nodes). You should be aware that there is no guarantee that multiple statements affecting privileges originating from different SQL nodes are executed on all SQL nodes in the same order. For this reason, it is highly recommended that all user administration be done from a single designated SQL node.
NDB_STORED_USER是一个全局权限,必须使用ON *.*来授予或撤销。尝试为该权限设置任何其他范围将导致错误。该权限可以授予大多数应用程序和管理用户,但不能授予系统保留账户,例如mysql.session@localhost或mysql.infoschema@localhost。NDB_STORED_USERis a global privilege and must be granted or revoked usingON *.*. Trying to set any other scope for this privilege results in an error. This privilege can be given to most application and administrative users, but it cannot be granted to system reserved accounts such asmysql.session@localhostormysql.infoschema@localhost.被授予
NDB_STORED_USER权限的用户会被存储在NDB中(因此所有 SQL 节点共享该用户),具有此权限的角色也是如此。仅仅被授予拥有NDB_STORED_USER权限的角色的用户 不会 存储在NDB中;每个NDB存储的用户必须显式授予该权限。A user that has been granted theNDB_STORED_USERprivilege is stored inNDB(and thus shared by all SQL nodes), as is a role with this privilege. A user that is merely granted a role that hasNDB_STORED_USERis not stored inNDB; eachNDBstored user must be granted the privilege explicitly.有关在
NDB中此功能的详细信息,请参见 第 25.6.13 节,“权限同步和 NDB_STORED_USER”。For more detailed information about how this works inNDB, see Section 25.6.13, “Privilege Synchronization and NDB_STORED_USER”.启用使用
OPTIMIZE LOCAL TABLE和OPTIMIZE NO_WRITE_TO_BINLOG TABLE语句。Enables use ofOPTIMIZE LOCAL TABLEandOPTIMIZE NO_WRITE_TO_BINLOG TABLEstatements.PASSWORDLESS_USER_ADMINPASSWORDLESS_USER_ADMIN此权限适用于无密码用户账户:This privilege applies to passwordless user accounts:
在创建账户时,执行
CREATE USER来创建无密码账户的用户必须拥有PASSWORDLESS_USER_ADMIN权限。For account creation, a user who executesCREATE USERto create a passwordless account must possess thePASSWORDLESS_USER_ADMINprivilege.在复制环境中,
PASSWORDLESS_USER_ADMIN权限适用于复制用户,并允许复制针对配置为无密码认证的用户账户的ALTER USER ... MODIFY语句。In replication context, thePASSWORDLESS_USER_ADMINprivilege applies to replication users and enables replication ofALTER USER ... MODIFYstatements for user accounts that are configured for passwordless authentication.
有关免密码认证的信息,请参见 WebAuthn 免密码认证。For information about passwordless authentication, see WebAuthn Passwordless Authentication.
对于同时拥有
SYSTEM_VARIABLES_ADMIN权限的用户,PERSIST_RO_VARIABLES_ADMIN允许使用SET PERSIST_ONLY将全局系统变量持久化到数据目录中的mysqld-auto.cnf配置文件中。此语句类似于SET PERSIST,但不会修改运行时的全局系统变量值。这使得SET PERSIST_ONLY适用于配置只能在服务器启动时设置的只读系统变量。For users who also haveSYSTEM_VARIABLES_ADMIN,PERSIST_RO_VARIABLES_ADMINenables use ofSET PERSIST_ONLYto persist global system variables to themysqld-auto.cnfoption file in the data directory. This statement is similar toSET PERSISTbut does not modify the runtime global system variable value. This makesSET PERSIST_ONLYsuitable for configuring read-only system variables that can be set only at server startup.另请参见 第 7.1.9.1 节,“系统变量权限”。See also Section 7.1.9.1, “System Variable Privileges”.
REPLICATION_APPLIERREPLICATION_APPLIER使账户能够作为复制通道的
PRIVILEGE_CHECKS_USER并在 mysqlbinlog 输出中执行BINLOG语句。将此权限授予使用CHANGE REPLICATION SOURCE TO分配的账户,以为复制通道提供安全上下文,并处理这些通道上的复制错误。除了REPLICATION_APPLIER权限外,您还必须授予账户执行复制通道接收的事务或 mysqlbinlog 输出中包含的事务所需的权限,例如更新受影响的表。有关更多信息,请参见 第 19.3.3 节,“复制权限检查”。Enables the account to act as thePRIVILEGE_CHECKS_USERfor a replication channel, and to executeBINLOGstatements in mysqlbinlog output. Grant this privilege to accounts that are assigned usingCHANGE REPLICATION SOURCE TOto provide a security context for replication channels, and to handle replication errors on those channels. As well as theREPLICATION_APPLIERprivilege, you must also give the account the required privileges to execute the transactions received by the replication channel or contained in the mysqlbinlog output, for example to update the affected tables. For more information, see Section 19.3.3, “Replication Privilege Checks”.REPLICATION_SLAVE_ADMINREPLICATION_SLAVE_ADMIN允许账户连接到复制源服务器,使用
START REPLICA和STOP REPLICA语句启动和停止复制,并使用CHANGE REPLICATION SOURCE TO和CHANGE REPLICATION FILTER语句。将此权限授予复本使用的账户,使其可以将当前服务器作为其复制源服务器进行连接。此权限不适用于组复制;请使用GROUP_REPLICATION_ADMIN。Enables the account to connect to the replication source server, start and stop replication using theSTART REPLICAandSTOP REPLICAstatements, and use theCHANGE REPLICATION SOURCE TOandCHANGE REPLICATION FILTERstatements. Grant this privilege to accounts that are used by replicas to connect to the current server as their replication source server. This privilege does not apply to Group Replication; useGROUP_REPLICATION_ADMINfor that.RESOURCE_GROUP_ADMINRESOURCE_GROUP_ADMIN启用资源组管理,包括创建、修改和删除资源组,以及将线程和语句分配到资源组。拥有此权限的用户可以执行与资源组相关的任何操作。Enables resource group management, consisting of creating, altering, and dropping resource groups, and assignment of threads and statements to resource groups. A user with this privilege can perform any operation relating to resource groups.
允许将线程和语句分配到资源组。拥有此权限的用户可以使用
SET RESOURCE GROUP语句和RESOURCE_GROUP优化器提示。Enables assigning threads and statements to resource groups. A user with this privilege can use theSET RESOURCE GROUPstatement and theRESOURCE_GROUPoptimizer hint.启用授予和撤销角色、使用
WITH ADMIN OPTION子句的GRANT语句,以及从<graphml>函数的结果中获取非空ROLES_GRAPHML()元素内容。设置mandatory_roles系统变量的值是必需的。Enables granting and revoking roles, use of theWITH ADMIN OPTIONclause of theGRANTstatement, and nonempty<graphml>element content in the result from theROLES_GRAPHML()function. Required to set the value of themandatory_rolessystem variable.允许持有者查看性能模式表中的敏感系统变量值,包括
global_variables、session_variables、variables_by_thread,以及persisted_variables,能够通过执行SELECT语句返回它们的值,并在会话跟踪器中跟踪它们的更改。没有该权限的用户无法查看或跟踪这些系统变量值。参见 持久化敏感系统变量。Enables a holder to view the values of sensitive system variables in the Performance Schema tablesglobal_variables,session_variables,variables_by_thread, andpersisted_variables, to issueSELECTstatements to return their values, and to track changes to them in session trackers for connections. Users without this privilege cannot view or track those system variable values. See Persisting Sensitive System Variables.启用对网络接口的连接,该接口仅允许管理连接(参见 第 7.1.12.1 节,“连接接口”)。Enables connections to the network interface that permits only administrative connections (see Section 7.1.12.1, “Connection Interfaces”).
对于大多数系统变量,设置会话值不需要特殊权限,任何用户都可以设置以影响当前会话。对于某些系统变量,设置会话值可能会对当前会话之外产生影响,因此这是一个受限制的操作。对于这些变量,
SESSION_VARIABLES_ADMIN权限允许用户设置会话值。For most system variables, setting the session value requires no special privileges and can be done by any user to affect the current session. For some system variables, setting the session value can have effects outside the current session and thus is a restricted operation. For these, theSESSION_VARIABLES_ADMINprivilege enables the user to set the session value.如果系统变量受到限制,并且设置会话值需要特殊权限,则变量描述会标明该限制。示例包括
binlog_format、sql_log_bin和sql_log_off。If a system variable is restricted and requires a special privilege to set the session value, the variable description indicates that restriction. Examples includebinlog_format,sql_log_bin, andsql_log_off.SESSION_VARIABLES_ADMIN权限是SYSTEM_VARIABLES_ADMIN和SUPER权限的一个子集。拥有其中任一权限的用户也被允许设置受限的会话变量,并且实际上隐含拥有SESSION_VARIABLES_ADMIN权限,因此无需显式授予SESSION_VARIABLES_ADMIN。TheSESSION_VARIABLES_ADMINprivilege is a subset of theSYSTEM_VARIABLES_ADMINandSUPERprivileges. A user who has either of those privileges is also permitted to set restricted session variables and effectively hasSESSION_VARIABLES_ADMINby implication and need not be grantedSESSION_VARIABLES_ADMINexplicitly.另请参见 第 7.1.9.1 节,“系统变量权限”。See also Section 7.1.9.1, “System Variable Privileges”.
允许在执行视图或存储程序时设置有效的授权 ID。具有此权限的用户可以将任何账户指定为
DEFINER属性,用于CREATE PROCEDURE、CREATE FUNCTION、CREATE TRIGGER、CREATE EVENT、ALTER EVENT、CREATE VIEW和ALTER VIEW。没有此权限时,只能指定有效的认证 ID。Enables setting the effective authorization ID when executing a view or stored program. A user with this privilege can specify any account as theDEFINERattribute forCREATE PROCEDURE,CREATE FUNCTION,CREATE TRIGGER,CREATE EVENT,ALTER EVENT,CREATE VIEW, andALTER VIEW. Without this privilege, only the effective authentication ID can be specified.存储程序以指定账户的权限执行,因此请确保遵循第 27.6 节,“存储对象访问控制”中列出的风险最小化指南。Stored programs execute with the privileges of the specified account, so ensure that you follow the risk minimization guidelines listed in Section 27.6, “Stored Object Access Control”.
允许用户访问所有存储例程(存储过程和函数)的定义和属性,即使用户未被指定为例程的
DEFINER。此访问包括:Enables a user to access definitions and properties of all stored routines (stored procedures and functions), even those for which the user is not named as the routineDEFINER. This access includes:信息模式中的
ROUTINES表的内容。The contents of the Information SchemaROUTINEStable.SHOW CREATE FUNCTION和SHOW CREATE PROCEDURE语句。TheSHOW CREATE FUNCTIONandSHOW CREATE PROCEDUREstatements.SHOW FUNCTION CODE和SHOW PROCEDURE CODE语句。TheSHOW FUNCTION CODEandSHOW PROCEDURE CODEstatements.SHOW FUNCTION STATUS和SHOW PROCEDURE STATUS语句。TheSHOW FUNCTION STATUSandSHOW PROCEDURE STATUSstatements.
SHOW_ROUTINE可以作为一种权限授予,范围更有限,允许访问例程定义。(也就是说,管理员可以取消不需要全局SELECT权限的用户,并改为授予SHOW_ROUTINE。) 这使得账户可以在不需要广泛权限的情况下备份存储的例程。SHOW_ROUTINEmay be granted instead as a privilege with a more restricted scope that permits access to routine definitions. (That is, an administrator can rescind globalSELECTfrom users that do not otherwise require it and grantSHOW_ROUTINEinstead.) This enables an account to back up stored routines without requiring a broad privilege.拥有此权限的用户发出的查询将不会被
Rewriter插件重写(参见 第 7.6.4 节,“Rewriter 查询重写插件”)。Queries issued by a user with this privilege are not subject to being rewritten by theRewriterplugin (see Section 7.6.4, “The Rewriter Query Rewrite Plugin”).此权限应授予发出不应被重写的管理或控制语句的用户,以及
PRIVILEGE_CHECKS_USER账户(参见 第 19.3.3 节,“复制权限检查”),用于应用来自复制源的语句。This privilege should be granted to users issuing administrative or control statements that should not be rewritten, as well as toPRIVILEGE_CHECKS_USERaccounts (see Section 19.3.3, “Replication Privilege Checks”) used to apply statements from a replication source.SYSTEM_USER权限区分系统用户和普通用户:TheSYSTEM_USERprivilege distinguishes system users from regular users:拥有
SYSTEM_USER权限的用户是系统用户。A user with theSYSTEM_USERprivilege is a system user.没有
SYSTEM_USER权限的用户是普通用户。A user without theSYSTEM_USERprivilege is a regular user.
SYSTEM_USER权限会影响特定用户可以对哪些账户应用其他权限,以及该用户是否受到其他账户的保护:TheSYSTEM_USERprivilege has an effect on the accounts to which a given user can apply its other privileges, as well as whether the user is protected from other accounts:系统用户可以修改系统账户和普通账户。也就是说,具有在普通账户上执行某项操作的适当权限的用户,通过拥有
SYSTEM_USER权限,也能够在系统账户上执行该操作。系统账户只能由具有适当权限的系统用户修改,普通用户不能修改。A system user can modify both system and regular accounts. That is, a user who has the appropriate privileges to perform a given operation on regular accounts is enabled by possession ofSYSTEM_USERto also perform the operation on system accounts. A system account can be modified only by system users with appropriate privileges, not by regular users.拥有适当权限的普通用户可以修改普通账户,但不能修改系统账户。普通账户可以被拥有适当权限的系统用户和普通用户修改。A regular user with appropriate privileges can modify regular accounts, but not system accounts. A regular account can be modified by both system and regular users with appropriate privileges.
这也意味着,具有
SYSTEM_USER权限的用户创建的数据库对象,不能被没有该权限的用户修改或删除。这也适用于定义者拥有此权限的例程。This also means that database objects created by users with theSYSTEM_USERprivilege cannot be modified or dropped by users without the privilege. This also applies to routines for which the definer has this privilege.欲了解更多信息,请参见 第 8.2.11 节,“账户类别”。For more information, see Section 8.2.11, “Account Categories”.
由
SYSTEM_USER权限为系统账户提供的防止普通账户修改的保护,不适用于拥有mysql系统模式权限的普通账户,因此这些账户可以直接修改该模式中的授权表。为了获得完整的保护,请不要向普通账户授予mysql模式权限。请参阅 防止普通账户操作系统账户。The protection against modification by regular accounts that is afforded to system accounts by theSYSTEM_USERprivilege does not apply to regular accounts that have privileges on themysqlsystem schema and thus can directly modify the grant tables in that schema. For full protection, do not grantmysqlschema privileges to regular accounts. See Protecting System Accounts Against Manipulation by Regular Accounts.如果正在使用
audit_log插件(参见 第 8.4.5 节,“MySQL 企业审计”),具有SYSTEM_USER权限的账户会自动被赋予AUDIT_ABORT_EXEMPT权限,这允许它们的查询即使被过滤器中配置的 “abort” 项阻止也能够执行。因此,具有SYSTEM_USER权限的账户可以用于在审计配置错误后恢复对系统的访问。If theaudit_logplugin is in use (see Section 8.4.5, “MySQL Enterprise Audit”), accounts with theSYSTEM_USERprivilege are automatically assigned theAUDIT_ABORT_EXEMPTprivilege, which permits their queries to be executed even if an “abort” item configured in the filter would block them. Accounts with theSYSTEM_USERprivilege can therefore be used to regain access to a system following an audit misconfiguration.影响以下操作和服务器行为:Affects the following operations and server behaviors:
在运行时启用系统变量更改:Enables system variable changes at runtime:
允许使用
SET GLOBAL和SET PERSIST对全局系统变量进行服务器配置更改。Enables server configuration changes to global system variables withSET GLOBALandSET PERSIST.允许用户在拥有
PERSIST_RO_VARIABLES_ADMIN权限的情况下,通过SET PERSIST_ONLY对全局系统变量进行服务器配置更改。Enables server configuration changes to global system variables withSET PERSIST_ONLY, if the user also hasPERSIST_RO_VARIABLES_ADMIN.启用设置受限的会话系统变量,这些变量需要特殊权限。实际上,
SYSTEM_VARIABLES_ADMIN隐含SESSION_VARIABLES_ADMIN,而无需显式授予SESSION_VARIABLES_ADMIN。Enables setting restricted session system variables that require a special privilege. In effect,SYSTEM_VARIABLES_ADMINimpliesSESSION_VARIABLES_ADMINwithout explicitly grantingSESSION_VARIABLES_ADMIN.
另请参见 第 7.1.9.1 节,“系统变量权限”。See also Section 7.1.9.1, “System Variable Privileges”.
允许更改全局事务特性(参见 第 15.3.7 节,“SET TRANSACTION 语句”)。Enables changes to global transaction characteristics (see Section 15.3.7, “SET TRANSACTION Statement”).
当
table_encryption_privilege_check启用时,允许用户覆盖默认的加密设置;参见 为模式和通用表空间定义加密默认值。Enables a user to override default encryption settings whentable_encryption_privilege_checkis enabled; see Defining an Encryption Default for Schemas and General Tablespaces.启用遥测日志配置。此权限由
telemetry_log插件定义,该插件通过 MySQL HeatWave 在 AWS 上部署。Enables telemetry log configuration. This privilege is defined by thetelemetry_logplugin, which is deployed through MySQL HeatWave on AWS.允许使用特权连接连接到服务器。当达到
thread_pool_max_transactions_limit定义的限制时,不允许新的连接,除非被thread_pool_longrun_trx_limit覆盖。特权连接会忽略事务限制,并允许连接到服务器以增加事务限制、移除限制或终止正在运行的事务。默认情况下,任何用户都不授予此特权。要建立特权连接,发起连接的用户必须拥有TP_CONNECTION_ADMIN特权。Enables connecting to the server with a privileged connection. When the limit defined bythread_pool_max_transactions_limithas been reached, new connections are not permitted, unless overridden bythread_pool_longrun_trx_limit. A privileged connection ignores the transaction limit and permits connecting to the server to increase the transaction limit, remove the limit, or kill running transactions. This privilege is not granted to any user by default. To establish a privileged connection, the user initiating a connection must have theTP_CONNECTION_ADMINprivilege.特权连接可以在达到
thread_pool_max_transactions_limit定义的限制时执行语句并启动事务。特权连接被放置在Admin线程组中。请参见特权连接。A privileged connection can execute statements and start transactions when the limit defined bythread_pool_max_transactions_limithas been reached. A privileged connection is placed in theAdminthread group. See Privileged Connections.在复制源服务器上将
gtid_next系统变量设置为AUTOMATIC:或TAGUUID:时所需。此外,要在源服务器上将TAG:NUMBERgtid_next设置为这些值之一,还至少需要具备SYSTEM_VARIABLES_ADMIN、SESSION_VARIABLES_ADMIN或REPLICATION_APPLIER中的一个权限。Required for setting thegtid_nextsystem variable toAUTOMATIC:orTAGUUID:on a replication source server. In addition, at least one ofTAG:NUMBERSYSTEM_VARIABLES_ADMIN,SESSION_VARIABLES_ADMIN, orREPLICATION_APPLIERis also required to setgtid_nextto one of these values on the source.REPLICATION_CHECKS_APPLIER还必须拥有此权限,以及REPLICATION_APPLIER权限,才能将gtid_next设置为AUTOMATIC:。在启动复制应用线程时会检查此权限。TheTAGREPLICATION_CHECKS_APPLIERmust also have this privilege as well as theREPLICATION_APPLIERprivilege to setgtid_nexttoAUTOMATIC:. This is checked when starting the replication applier thread.TAG设置服务器系统变量
gtid_purged也需要此权限。This privilege is also required to set thegtid_purgedserver system variable.有关使用带标签 GTID 的更多信息,请参阅
gtid_next的说明,以及 第 19.1.4 节,“在线服务器上更改 GTID 模式”。For more information about using tagged GTIDs, see the description ofgtid_next, as well as Section 19.1.4, “Changing GTID Mode on Online Servers”.启用执行版本令牌功能。此权限由
version_tokens插件定义;详见 第 7.6.6 节,“版本令牌”。Enables execution of Version Tokens functions. This privilege is defined by theversion_tokensplugin; see Section 7.6.6, “Version Tokens”.启用执行
XA RECOVER语句;详见 第 15.3.8.1 节,“XA 事务 SQL 语句”。Enables execution of theXA RECOVERstatement; see Section 15.3.8.1, “XA Transaction SQL Statements”.在 MySQL 8.4 之前,任何用户都可以执行
XA RECOVER语句来发现未完成的准备好的 XA 事务的 XID 值,这可能导致除了启动事务的用户以外的其他用户提交或回滚 XA 事务。在 MySQL 8.4 中,XA RECOVER仅允许具有XA_RECOVER_ADMIN权限的用户执行,这种权限通常只授予需要它的管理用户。例如,如果 XA 应用程序崩溃,需要找到应用程序启动的未完成事务以便回滚,这种情况可能会出现。此权限要求防止用户发现除自己之外的未完成准备好的 XA 事务的 XID 值。它不会影响 XA 事务的正常提交或回滚,因为启动该事务的用户知道其 XID。Prior to MySQL 8.4, any user could execute theXA RECOVERstatement to discover the XID values for outstanding prepared XA transactions, possibly leading to commit or rollback of an XA transaction by a user other than the one who started it. In MySQL 8.4,XA RECOVERis permitted only to users who have theXA_RECOVER_ADMINprivilege, which is expected to be granted only to administrative users who have need for it. This might be the case, for example, for administrators of an XA application if it has crashed and it is necessary to find outstanding transactions started by the application so they can be rolled back. This privilege requirement prevents users from discovering the XID values for outstanding prepared XA transactions other than their own. It does not affect normal commit or rollback of an XA transaction because the user who started it knows its XID.
建议只向账户授予其所需的权限。在授予 FILE 和管理权限时应特别谨慎:It is a good idea to grant to an account only those privileges
that it needs. You should exercise particular caution in
granting the FILE and
administrative privileges:
FILE可能被滥用来读取表中 MySQL 服务器在服务器主机上可以访问的任何文件。这包括所有可被全世界读取的文件以及服务器数据目录中的文件。然后可以使用SELECT访问该表,将其内容传输到客户端主机。FILEcan be abused to read into a database table any files that the MySQL server can read on the server host. This includes all world-readable files and files in the server's data directory. The table can then be accessed usingSELECTto transfer its contents to the client host.GRANT OPTION允许用户将他们的权限授予其他用户。两个拥有不同权限且具有GRANT OPTION权限的用户能够合并权限。GRANT OPTIONenables users to give their privileges to other users. Two users that have different privileges and with theGRANT OPTIONprivilege are able to combine privileges.ALTER可用于通过重命名表来规避权限系统。ALTERmay be used to subvert the privilege system by renaming tables.SHUTDOWN可能被滥用,通过终止服务器完全拒绝其他用户的服务。SHUTDOWNcan be abused to deny service to other users entirely by terminating the server.PROCESS可以用来查看当前正在执行的语句的明文,包括设置或更改密码的语句。PROCESScan be used to view the plain text of currently executing statements, including statements that set or change passwords.SUPER可以用来终止其他会话或更改服务器的操作方式。SUPERcan be used to terminate other sessions or change how the server operates.授予
mysql系统数据库本身的权限可以用来更改密码和其他访问权限信息:Privileges granted for themysqlsystem database itself can be used to change passwords and other access privilege information:密码是以加密形式存储的,因此恶意用户无法简单读取以得知明文密码。然而,具有写权限的用户可以修改
mysql.user系统表的authentication_string列,从而更改账户的密码,然后使用该账户连接到 MySQL 服务器。Passwords are stored encrypted, so a malicious user cannot simply read them to know the plain text password. However, a user with write access to themysql.usersystem tableauthentication_stringcolumn can change an account's password, and then connect to the MySQL server using that account.INSERT或UPDATE授予mysql系统数据库的权限分别允许用户添加权限或修改现有权限。INSERTorUPDATEgranted for themysqlsystem database enable a user to add privileges or modify existing privileges, respectively.DROP对mysql系统数据库的权限允许用户删除权限表,或者甚至删除整个数据库。DROPfor themysqlsystem database enables a user to remote privilege tables, or even the database itself.
MySQL 支持静态和动态权限:MySQL supports static and dynamic privileges:
静态权限内置于服务器中。它们始终可以授予用户账户,且无法注销。Static privileges are built in to the server. They are always available to be granted to user accounts and cannot be unregistered.
动态权限可以在运行时注册和注销。这会影响它们的可用性:未注册的动态权限无法被授予。Dynamic privileges can be registered and unregistered at runtime. This affects their availability: A dynamic privilege that has not been registered cannot be granted.
例如,SELECT 和 INSERT 权限是静态的且始终可用,而动态权限只有在实现它的组件已启用时才可用。For example, the SELECT and
INSERT privileges are static and
always available, whereas a dynamic privilege becomes available
only if the component that implements it has been enabled.
本节的其余部分描述了 MySQL 中动态权限的工作原理。讨论中使用了术语 “组件”,但同样适用于插件。The remainder of this section describes how dynamic privileges work in MySQL. The discussion uses the term “components” but applies equally to plugins.
服务器管理员应了解哪些服务器组件定义了动态权限。对于 MySQL 发行版,定义动态权限的组件的文档会描述这些权限。Server administrators should be aware of which server components define dynamic privileges. For MySQL distributions, documentation of components that define dynamic privileges describes those privileges.
第三方组件也可能定义动态权限;管理员应了解这些权限,并避免安装可能冲突或影响服务器运行的组件。例如,当两个组件都定义同名权限时,它们会产生冲突。组件开发者可以通过选择以组件名称为前缀的权限名称来降低此类情况发生的可能性。Third-party components may also define dynamic privileges; an administrator should understand those privileges and not install components that might conflict or compromise server operation. For example, one component conflicts with another if both define a privilege with the same name. Component developers can reduce the likelihood of this occurrence by choosing privilege names having a prefix based on the component name.
服务器在内存中维护已注册动态权限的集合。注销发生在服务器关闭时。The server maintains the set of registered dynamic privileges internally in memory. Unregistration occurs at server shutdown.
通常,定义动态权限的组件会在安装时,在其初始化序列中注册这些权限。当组件卸载时,它不会注销其已注册的动态权限。(这是当前做法,而非要求。也就是说,组件可以在任何时候注销它们注册的权限,但实际上通常不这样做。)Normally, a component that defines dynamic privileges registers them when it is installed, during its initialization sequence. When uninstalled, a component does not unregister its registered dynamic privileges. (This is current practice, not a requirement. That is, components could, but do not, unregister at any time privileges they register.)
尝试注册一个已注册的动态权限不会产生警告或错误。考虑以下语句序列:No warning or error occurs for attempts to register an already registered dynamic privilege. Consider the following sequence of statements:
INSTALL COMPONENT 'my_component'; UNINSTALL COMPONENT 'my_component'; INSTALL COMPONENT 'my_component';
第一个 INSTALL COMPONENT 语句会注册组件 my_component 定义的任何权限,但 UNINSTALL COMPONENT 不会注销这些权限。对于第二个 INSTALL
COMPONENT 语句,它注册的组件权限已发现已被注册,但不会产生任何警告或错误。The first INSTALL COMPONENT
statement registers any privileges defined by component
my_component, but
UNINSTALL COMPONENT does not
unregister them. For the second INSTALL
COMPONENT statement, the component privileges it
registers are found to be already registered, but no warnings or
errors occur.
动态权限仅在全局级别适用。服务器将在 mysql.global_grants 系统表中存储已分配给用户账户的当前动态权限信息:Dynamic privileges apply only at the global level. The server
stores information about current assignments of dynamic
privileges to user accounts in the
mysql.global_grants system table:
服务器在启动期间会自动注册
global_grants中列出的权限(除非提供了--skip-grant-tables选项)。The server automatically registers privileges named inglobal_grantsduring server startup (unless the--skip-grant-tablesoption is given).GRANT和REVOKE语句会修改global_grants的内容。TheGRANTandREVOKEstatements modify the contents ofglobal_grants.列在
global_grants中的动态权限分配是持久的。它们在服务器关闭时不会被移除。Dynamic privilege assignments listed inglobal_grantsare persistent. They are not removed at server shutdown.
示例:以下语句授予用户 u1 控制副本(包括组复制)所需的权限,并可修改系统变量:Example: The following statement grants to user
u1 the privileges required to control
replication (including Group Replication) on a replica, and to
modify system variables:
GRANT REPLICATION_SLAVE_ADMIN, GROUP_REPLICATION_ADMIN, BINLOG_ADMIN ON *.* TO 'u1'@'localhost';
授予的动态权限会出现在 SHOW GRANTS 语句的输出以及 INFORMATION_SCHEMA USER_PRIVILEGES 表中。Granted dynamic privileges appear in the output from the
SHOW GRANTS statement and the
INFORMATION_SCHEMA
USER_PRIVILEGES table.
对于全局级别的 GRANT 和 REVOKE,任何未被识别为静态的命名权限都会与当前注册的动态权限集进行检查,如果找到则授予。否则,将发生错误以指示未知的权限标识符。For GRANT and
REVOKE at the global level, any
named privileges not recognized as static are checked against
the current set of registered dynamic privileges and granted if
found. Otherwise, an error occurs to indicate an unknown
privilege identifier.
对于 GRANT 和 REVOKE,在全局级别上,ALL [PRIVILEGES] 的含义包括所有静态全局权限以及所有当前已注册的动态权限:For GRANT and
REVOKE the meaning of
ALL [PRIVILEGES] at the global level includes
all static global privileges, as well as all currently
registered dynamic privileges:
GRANT ALL在全局级别授予所有静态全局权限和所有当前已注册的动态权限。在执行GRANT语句之后注册的动态权限不会追溯授予任何账户。GRANT ALLat the global level grants all static global privileges and all currently registered dynamic privileges. A dynamic privilege registered subsequent to execution of theGRANTstatement is not granted retroactively to any account.REVOKE ALL在全局级别撤销所有已授予的静态全局权限和所有已授予的动态权限。REVOKE ALLat the global level revokes all granted static global privileges and all granted dynamic privileges.
FLUSH PRIVILEGES 语句读取 global_grants 表以进行动态权限分配,并注册其中发现的任何未注册权限。The FLUSH PRIVILEGES statement
reads the global_grants table for dynamic
privilege assignments and registers any unregistered privileges
found there.
有关 MySQL Server 提供的动态权限以及包含在 MySQL 发行版中的组件提供的动态权限的描述,请参见 第 8.2.2 节,“MySQL 提供的权限”。For descriptions of the dynamic privileges provided by MySQL Server and components included in MySQL distributions, see Section 8.2.2, “Privileges Provided by MySQL”.
在 MySQL 8.4 中,许多以前需要 SUPER 权限的操作,现在也与范围更有限的动态权限相关联。(有关这些权限的描述,请参见 第 8.2.2 节,“MySQL 提供的权限”。)可以通过授予相关的动态权限而不是 SUPER 来允许账户执行每个此类操作。此更改通过使 DBA 能够避免授予 SUPER 并更精确地为用户分配操作权限,从而提高了安全性。SUPER 现已弃用;预计将在未来的 MySQL 版本中移除。In MySQL 8.4, many operations that previously
required the SUPER privilege are
also associated with a dynamic privilege of more limited scope.
(For descriptions of these privileges, see
Section 8.2.2, “Privileges Provided by MySQL”.) Each such operation can
be permitted to an account by granting the associated dynamic
privilege rather than SUPER. This
change improves security by enabling DBAs to avoid granting
SUPER and tailor user privileges
more closely to the operations permitted.
SUPER is now deprecated; expect
it to be removed in a future version of MySQL.
当移除 SUPER 时,以前需要 SUPER 的操作将失败,除非将授予 SUPER 的账户迁移到适当的动态权限。请使用以下说明来完成此目标,以便在移除 SUPER 之前准备好账户:When removal of SUPER occurs,
operations that formerly required
SUPER fail unless accounts
granted SUPER are migrated to the
appropriate dynamic privileges. Use the following instructions
to accomplish that goal so that accounts are ready prior to
SUPER removal:
执行此查询以识别已授予
SUPER的账户:Execute this query to identify accounts that are grantedSUPER:SELECT GRANTEE FROM INFORMATION_SCHEMA.USER_PRIVILEGES WHERE PRIVILEGE_TYPE = 'SUPER';
对于前一个查询识别的每个账户,确定其需要
SUPER的操作。然后授予对应于这些操作的动态权限,并撤销SUPER。For each account identified by the preceding query, determine the operations for which it needsSUPER. Then grant the dynamic privileges corresponding to those operations, and revokeSUPER.例如,如果
'u1'@'localhost'在二进制日志清理和系统变量修改中需要SUPER权限,这些语句会对账户进行所需更改:For example, if'u1'@'localhost'requiresSUPERfor binary log purging and system variable modification, these statements make the required changes to the account:GRANT BINLOG_ADMIN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'u1'@'localhost'; REVOKE SUPER ON *.* FROM 'u1'@'localhost';
在您修改了所有适用账户后,第一步中的
INFORMATION_SCHEMA查询应产生空结果集。After you have modified all applicable accounts, theINFORMATION_SCHEMAquery in the first step should produce an empty result set.