MySQL创建及授权账号

grant all on . to wen@“localhost” identified by “111111”;
grant 授权命令
all 对应权限
on . 目标:库和表
to wen@“localhost” 用户名和客户端主机
identified by “111111” 用户密码

操作案例:创建master用户对test库具备所有权限,允许从localhost主机登录管理数据库,密码为master123
mysql> grant all on test.* to master@“localhost” identified by “master123”;
mysql> flush privileges;
授权后查看用户
mysql> select user,host from mysql.user;
查看授权用户权限
mysql> show grants for master@localhost;

额外添加管理员账号
grant all privileges on . to gao@“localhost” identified by ‘111111’ with grant option;
with grant option 这个参数表示gao这个用户有授权权限
mysql> flush privileges;
mysql> select user,host from mysql.user;
±-----±----------+
| user | host |
±-----±----------+
| root | 127.0.0.1 |
| gao | localhost |
| root | localhost |

撤销用户授权 revoke
revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:
1 grant all on . to dba@localhost;
2 revoke all on . from dba@localhost;

单独创建用户不授权
mysql> create user gao@localhost identified by ‘123’;

猜你喜欢

转载自blog.csdn.net/bjgaocp/article/details/87948980