1. 用root用户登录mysql
mysql -uroot -p123456
2. 添加用户 % 表示自动选择可用IP 增加登录用户(可允许登录的ip地址,只能登录,什么都不能做)
create user ‘username’@‘host’ identified by ‘password’;
3. 授权
grant 权限列表 on 库.表 to "用户名"@"%" identified by "密码" with grant option;
4. 刷新权限
flush privileges;
权限列表**
```
all privileges 、select 、insert ... ...
库.表 : *.* 代表所有库的所有表
```
**示例**
```mysql
1、添加授权用户work,密码123,对所有库的所有表有所有权限
mysql>grant all privileges on *.* to 'work'@'%' identified by '123' with grant option;
mysql>flush privileges;
2、添加用户duty,密码123,对db2库中所有表有所有权限
mysql>grant all privileges on db2.* to 'duty'@'%' identified by '123' with grant option;
mysql>flush privileges;