MySQL授权(grant)和撤销授权(revoke)的简单示例

前端之家收集整理的这篇文章主要介绍了MySQL授权(grant)和撤销授权(revoke)的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!

创建一个用户tom,密码为tom:

insert into user(host,user,password) values('localhost','tom',password('tom'));

创建数据库tom_db:

GBK: create database `tom_db` default character set gbk collate gbk_chinese_ci;
UTF8: create database `tom_db` default character set utf8 collate utf8_general_ci;

用户tom赋予所有库的所有权限:

grant all privileges on *.* to tom@localhost identified by 'tom';
grant all privileges on *.* to tom@"%" identified by 'tom';

授权用户tom拥有数据库tom_db的所有权限:

grant all privileges on tom_db.* to tom@localhost identified by "tom";
grant all privileges on tom_db.* to tom@"%" identified by "tom";

授权用户tom拥有数据库tom_db的部分权限:

grant select,insert,update,delete on tom_db.* to tom@localhost identified by 'tom';
grant select,delete on tom_db.* to tom@"%" identified by 'tom';

重新载入赋权表:

flush privileges;

查看当前用户(自己)权限:

show grants;

查看其他 MysqL 用户权限:

show grants for tom@localhost;

撤销已经赋予给 MysqL 用户权限的权限:

revoke all on *.* from tom@localhost;
revoke all on tom_db.* from tom@localhost;

如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 "grant option":

grant select on tom_db.* to tom@localhost with grant option;

猜你在找的MySQL相关文章