Mysql创建用户并授权

运行命令行

mysql -uroot -p

登录mysql

use mysql;

创建用户:
create user 'test123'@'localhost' identified by '12345';
这里的test123表示User,localhost表示Host,12345表示authentication_string(密码)

授权:
grant all privileges on *.* to 'test123'@'localhost';
这里的*.* 可以改成 testdb.*,testdb 表示具体的某一个库,testdb.*表示 testdb库的所有表
这里的all privileges表示所有权限,权限分为:select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限
所以这里也可以这样授权:
grant select,insert,update,delete on *.* to 'test123'@'localhost';


grant select,insert,update,delete,create,alter,drop on testdb.* to 'test123'@'localhost';

撤消授权:

revoke all on *.* from 'test123'@'localhost';

刷新:

flush privileges;

做完增删改之后都要记得刷新授权

查看用户操作权限:
show grants for 'test123'@'localhost';

 

posted @ 2016-09-03 08:58  O青梅煮酒O  阅读(396)  评论(0编辑  收藏  举报