The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

发布时间 2023-05-25 16:07:54作者: PiscesCanon

 

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

 

默认情况下,启动MySQL数据库实例期间,会读取所有的权限表条目到内存中,后续被缓存到内存中的权限条目作为依据即刻对后续的控制访问生效(传送门)。

使用"skip-grant-tables"启动MySQL数据库实例时,会禁用权限系统(MySQL privilege system),禁用身份验证检查(忘记root密码的常规重置操作,官档提供了此方式:传送门)。

这将导致无法使用如:"ALTER USER"、"CREATE USER"、"DROP USER"、"GRANT"、"REVOKE"、"SHOW GRANTS"等引起内部递归SQL后操作到权限表的DCL语法。

示例:

(root@ 15:31:09) [mysql]> create user 'test'@'%' identified by 'test';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

 

 

此时可以通过flush privileges在线重新启动权限系统(MySQL privilege system),对于"FLUSH PRIVILEGES",详见:传送门

这是因为这里flush privileges会重新触发读取所有的权限表条目到内存中这个动作。

或者通过OS层面执行mysqladmin flush-privilegesmysqladmin reload达到同样的效果。

(root@ 15:45:45) [mysql]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

(root@ 15:45:49) [mysql]> create user 'test'@'%' identified by 'test';
Query OK, 0 rows affected (0.01 sec)

 

 

实际上,这也是直接通过DML(delete/update/insert)操作授权表,(不重启数据库的前提下)需要执行"flush privileges"更新内存中权限条目达到即时生效的效果。

而通过"ALTER USER"、"CREATE USER"、"DROP USER"、"GRANT"、"REVOKE"等账户管理语句来直接间接修改权限时,服务器会注意到这些更改并立即将授权表再次加载到内存中。

详见:更改权限生效时机

防爬虫:https://www.cnblogs.com/PiscesCanon/p/17431610.html