MySql 5.7+【创建新用户】以及【授权】

2020-06-11  本文已影响0人  黑铁大魔王

首先:切换到mysql库

use mysql;

添加用户

//允许指定ip连接
create user '用户名'@'localhost' identified by '密码';

//允许所有ip连接(%表示所有ip)
create user 'demo'@'%' identified by 'demo';

授权

grant all privileges on 数据库名.表名 to '用户名'@'指定ip' identified by '密码' ;

// *表示所有
grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;

设置操作权限

// 设置所有权限
grant all privileges on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;

// 设置select权限
grant select on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;

// 其他权限: select, insert, delete, update用都好隔开
grant select,insert on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;

// 取消用户select权限
REVOKE select ON what FROM '用户名';

删除用户

DROP USER username@localhost;

修改后刷新

FLUSH PRIVILEGES;

全套操作:

use mysql;
create user 'demo'@'%' identified by 'demo';
grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;
grant all privileges on *.* to 'demo'@'%' identified by 'demo' WITH GRANT OPTION;
FLUSH PRIVILEGES;
上一篇下一篇

猜你喜欢

热点阅读