MySQL用户和权限管理
#1 用户管理
创建cpb@localhost用户,密码是mysql :
create user cpb@localhost identified by 'mysql';
删除用户:
drop user 'cpb'@'localhost';
查看有什么用户:
select user.host from mysql.user;
查询全部用户的信息:
select user,host, authentication_string from user;
Mysql查找密码:
grep 'temporary password' /var/log/mysql.log
2 权限管理
查看root@'localhost’有什么权限:
show grants for root@‘localhost’;
给cpb用户任意网段授权abc库的所有表 所有权限:
grant all on abc.* to cpb@’%’ identified by ‘123456’;
刷新授权:
flush privileges;
关闭授权:
revoke all on abc.* from cpb@’%’;
给cpb用户授权 user_0库的查询权限:
grant select on user_0.* to cpb@’%’ identified by ‘123456’;
给 ‘test’用户任意网段授权’tsetdb’库的建库表、改、删除库表视图、查、写、更新、删除数据 权限:
grant create,alter,drop,select,insert,update,delete on testdb.* to test@’%’;
授予用户test通过外网IP对数据库“testdb”的全部权限:
grant all privileges on ‘testdb’.* to ‘test’@’%’ identified by ‘1234’;
授予用户“test”通过外网IP对于该数据库“testdb”中表的创建、修改、删除权限,以及表数据的增删查改权限:
grant create,alter,drop,select,insert,update,delete on testdb.* to test@’%’;