1.创建账号并赋权
grant 权限(all privileges(除了grant)|insert|select|.....) on DB.table(*.*) to 'user'@'ip'(%,localhost,具体ip) [identified by 'password'] with grant option];
eg:grant all privileges on *.* to z1@localhost identified by '123' with grant option;
2.查看账号权限
show grants for user@ip;
show grants for user = show grants for user@%;
3.更改账号权限
(1):增加权限:首先查看账号权限,在使用第一步的语法赋权。
(2):回收权限:首先查看账号权限,在使用如下语法回收权限:
revoke 权限(all privileges(除了grant)|insert|select|grant option|.....) on DB.table(*.*) from 'user'@'ip'(%,localhost,具体ip);
注:usage权限不能回收,也就是说,revoke不能用来删除用户。
4.修改账号密码
(1) shell>mysqladmin -u use_name -h host_name password 'newpassword'
(2) msyql>set password for 'user'@'ip' = password('newpassword');
(3) msyql> set password = password('newpassword'); ---仅用来修改当前登入账户的密码
(4) grant usage on *.* to 'user'@'ip' identified by 'newpassword';
(5) 直接修改mysql数据库的user表: insert into user(host,user,password) values('%','user',password('newpassword'));
如果已存在,使用update user set password=password('newpassword') where host = '%(ip)' and user = 'user';
5.删除账号
(1)首先查看账号权限,找到user@ip的形式,然后drop user user@ip;
(2)进去mysql数据,然后删除user表的用户。
注:以上操作,在mysql交互式,命令下执行完,要记得执行:
mysql>flush privileges;