简体   繁体   English

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

[英]Revoke all privileges for all users on a MySQL DB

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? 那么问题就变成了,你如何撤销MySQL数据库上所有用户的所有权限? I imagine it's simple, but I'm surprised I haven't been able to find this anywhere. 我想这很简单,但我很惊讶我无法在任何地方找到它。

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. 但是不确定是否有办法同时为所有用户执行此操作。

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'@'%';

I suppose you can do: 我想你可以这样做:

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

(Don't modify MySQL tables directly) (不要直接修改MySQL表)

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 在执行之前

USE mysql; 
DELETE * FROM user;
FLUSH PRIVILEGES;

... will delete all users, including root and whatever you're connecting with, so you might want to add a WHERE clause. ...将删除所有用户,包括root和您正在连接的任何用户,因此您可能希望添加WHERE子句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM