撤销所有用户在 MySQL 数据库上的所有权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5287377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:05:40  来源:igfitidea点击:

Revoke all privileges for all users on a MySQL DB

mysql

提问by mlissner

From: http://dev.mysql.com/doc/refman/5.0/en/drop-database.html

来自:http: //dev.mysql.com/doc/refman/5.0/en/drop-database.html

...when a database is dropped, user privileges on the database are not automatically dropped.

...删除数据库时,不会自动删除数据库的用户权限。

So the question becomes, how do you revoke all privileges for all users on a MySQL DB? I imagine it's simple, but I'm surprised I haven't been able to find this anywhere.

那么问题就变成了,如何撤销 MySQL 数据库上所有用户的所有权限?我想这很简单,但我很惊讶我无法在任何地方找到它。

回答by Matt Ball

You can revoke all privileges for a specific user with this syntax:

您可以使用以下语法撤销特定用户的所有权限:

REVOKE ALL PRIVILEGES, GRANT OPTION FROM user [, user] ...
FLUSH PRIVILEGES;

which drops all global, database, table, column, and routine privileges for the named user or users

删除指定用户的所有全局、数据库、表、列和例程权限

Not sure if there's a way to do this for all users at once, though.

不过,不确定是否有办法同时为所有用户执行此操作。

回答by Iasmini Gomes

REVOKE ALL PRIVILEGES ON *.* FROM '<user_name>'@'localhost';
REVOKE ALL PRIVILEGES ON *.* FROM '<user_name>'@'%';

Eg.:

例如。:

REVOKE ALL PRIVILEGES ON *.* FROM 'jeffrey'@'localhost';
REVOKE ALL PRIVILEGES ON *.* FROM 'jeffrey'@'%';

回答by Federico

I suppose you can do:

我想你可以这样做:

REVOKE ALL PRIVILEGES FROM '%'@'%';
FLUSH PRIVILEGES;

(Don't modify MySQL tables directly)

(不要直接修改MySQL表)

回答by tkam

REVOKE ALL PRIVILEGES FROM '%'@'%';

The above could be dangerous as i suppose it will delete all the privileges from all the users including root

以上可能很危险,因为我认为它会删除所有用户的所有权限,包括 root

Modify it to:

修改为:

REVOKE ALL PRIVILEGES FROM 'user'@'localhost';

or

或者

REVOKE ALL PRIVILEGES FROM 'user'@'%';

before execute

执行前