mysql grant使用

grant  super,reload on  my_test.* to forslave@192.168.142.137 identified by '123456'; 

1  %与localhost使用 

有些时候(有些版本)'%'不包括localhost,要单独对@'localhost'进行赋值,分别对'%'和'localhost'授权解决。

有的时候使用Grant all on db.* to user identified by "pass"后,在主机上访问数据库还会出现ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES) 的错误提示?
则使用: Grant all on db.* to 'user'@'localhost' identified by "pass"
因为:当不加@选项时,效果与加@'%'是一样的,'%'从名义上包括任何主机,(%必须加上引号,不然与@放在一起可能不会被辨认出。)不过有些时候(有些版本)'%'不包括localhost,要单独对@'localhost'进行赋值

2 grant 赋予权限使用:  grant 权限 on 数据库对象 to 用户

 grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。

 grant select, insert, update, delete on testdb.* to common_user@'%'

 grant create,alert,dorp  on testdb.* to developer@'192.168.0.%';

3 普通DBA  管理某个 MySQL 数据库的权限。

grant all privileges on testdb to dba@'localhost'

四、grant 高级 DBA 管理 MySQL 中所有数据库的权限。

grant all on *.* to dba@'localhost'     //*.*  第一个* 是数据库,第二个*是表 *.* 是所有库的所有表 

六、查看 MySQL 用户权限

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

查看其他 MySQL 用户权限: show grants for dba@localhost;

七、撤销已经赋予给 MySQL 用户权限的权限。

revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:

grant  all on *.* to   dba@localhost;

revoke all on *.* from dba@localhost;

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

grant select on testdb.* to dba@localhost with grant option;

九、通过grant 来增加管理用户test2,密码为123456

grant select,insert,update,delete on mydb.* to test2@localhost identified by "123456";

  

 十、windows上的mysql不能用远程用ip来访问,将访问者ip放到权限中心,就可以访问了(101.168.34.18访问者ip)

    

select host, user from user;

grant all privileges on *.* to root@"101.168.34.18" identified by "root";
flush privileges;