MySQL 权限笔记

revoke    riˈvōk        撤销

put an end to the validity or operation of (a decree, decision, or promise).

privilege    ˈpriv(ə)lij    特权

a special right, advantage, or immunity granted or available only to a particular person or group of people.
education is a right, not a privilege

grant    发放

a sum of money given by an organization, especially a government, for a particular purpose.
The money is used for small grants to deserving organizations and individuals.
 
 

本文的注释全是为了方便起见而写,sql不是这样注释的。

create user 'u1'@'localhost' identified by '12345';//在localhost 创建一个叫u1的用户, 密码为12345

set password for 'u1'@'localhost' = '12345';    //将密码设置为12345
GRANT select ON book_reader_db.book TO 'u1'@'localhost';  //给u1 赋予在book表内select的权限
revoke select on what from 'u1'@'localhost';
grant all privileges on book_reader_db.* to 'u1'@'localhost';  //给u1 操作数据库所有表的权限
revoke all privileges on book_reader_db.* from 'u1'@'localhost';//取消权限
revoke all on book_reader_db.* from 'u1'@'localhost';    //少写一个privileges...最好还是把这个单词背下来。。。
flush privileges;    //刷新权限

show grants for 'u1'@'localhost';   //显示u1的所有权限
GRANT SELECT ON `book_reader_db`.`book` TO `u1`@`localhost` WITH GRANT OPTION    //给u1权限的同时也让u1有权力给别的用户权限。


grant  create user on *.*  to 'user'@'host';     赋予创建用户的权限。

revoke create user on *.* from 'u1'@'localhost';   删除创建用户的权限。

上面3条语句都需要重启数据库才能生效

至于怎样重启数据库。。。

打开命令行输入net stop mysqlnet start mysql 就好。。。

我现在在也很想知道怎么撤销给别人权限的权限,除了用revoke all.....

select * from mysql.user;

显示所有的用户

show grants for 'u1'@'localhost';

显示特定用户的权限

原文地址:https://www.cnblogs.com/incredible-x/p/10045300.html