1. 创建新用户

create user 'username'@'host' identified by 'password';

其中username为自定义的用户名;host为登录域名,%代表任意IP,localhost代表本机,或者填写指定的IP地址;password为密码

2. 为用户授权

grant all privileges on *.* to 'username'@'host' with grant option;

其中*.*第一个*表示所有数据库,第二个*表示所有数据表,如果不想授权全部那就把对应的*写成相应数据库或者数据表;username为指定的用户;%为该用户登录的域名

3. 授权之后刷新权限

flush privileges;

4. 撤销授权

# 收回权限(不包含赋权权限)
revoke all privileges on *.* from user_name;
revoke all privileges on user_name.* from user_name;
# 收回赋权权限
revoke grant on option on *.* from user_name;
# 操作完成后重新刷新权限
flush privileges;