gpt4 book ai didi

mysql - 撤销对不再存在的表的 MySQL 权限

转载 作者:行者123 更新时间:2023-12-01 03:40:12 25 4
gpt4 key购买 nike

我创建了一个具有表级权限的 mysql 用户。

这张表一段时间后被删除,但mysql.table_priv中的权限仍然存在。

有没有办法(也许是 StoredProcedure)删除 mysql.table priv 中所有引用不存在的表的条目?

这是一种重现它的方法:

CREATE DATABASE test;
USE test;
CREATE TABLE test (Col1 INT(10));
GRANT SELECT ON test.test TO test@'%' IDENTIFIED BY 'test';
DROP TABLE test;


SELECT * FROM mysql.tables_priv WHERE user = 'test'; # 1 row

你好
安德烈

最佳答案

您可以使用以下查询在不再存在的表上查找用户的所有权限:

SELECT tables_priv.* FROM mysql.tables_priv 
LEFT JOIN information_schema.tables ON (db=table_schema AND tables_priv.table_name=tables.table_name)
WHERE tables.table_schema IS NULL;

之后您可以使用 DELETE删除权限:
DELETE mysql.tables_priv FROM mysql.tables_priv 
LEFT JOIN information_schema.tables
ON (db=table_schema AND tables_priv.table_name=tables.table_name)
WHERE tables.table_schema IS NULL;
FLUSH PRIVILEGES;

我希望我不必说这些,但请务必小心使用。

关于mysql - 撤销对不再存在的表的 MySQL 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31470439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com