1 建立用户
mysql>create user 'username'@'host' identified by 'password';
host 指定用户登录位置, 本机登录为localhost, 任意主机为%
2 用户授权
mysql>grant privileges on dbname.tbname to 'username'@'host';
privileges 权限列表
GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
--------------------------------------------------------------------------------------------------------
创建用户并授权
mysql>grant privileges on dbname.tbname to 'username'@'host' identified by 'password' with grant option
privileges 权限列表
with grant option 是授权给用户可以继续给他人授权
--------------------------------------------------------------------------------------------------------
3 设置密码
mysql>set password for 'username'@'host' =password('password');
对当前登录用户设置密码: set password = password('password');
4 撤销授权
mysql>revoke privileges on dbname.tbname to 'username'@'host';
通授权模式
5 删除用户
mysql>drop user 'username'@'host';
6 设置生效
mysql>flush privileges;