mysql用户管理

mysql中 将于用户相关的数据放在mysql库

user - > db - > tables_priv -> columns_priv
如果用户拥有对所有库的访问权 则存储在 user中
如果用户拥有对部分库的使用权 db
如果用户拥有对部分表的使用权 tables;
如果用户拥有对表中某些字段的使用权 columns_priv中

创建新账户

create user "账户名"@"主机名" identified by 密码
create user "tom"@"localhost" identified by "123";

授权

授予所有数据库所有表的所有权限给jerry这个用户 并允许jerry在任意一台电脑登录
如果用户不存在会自动创建
grant all on *.* to "jerry"@"%" identified by "123" with grant option;
with grant option这个用户可以将拥有的权限授予别人

授予day45数据库所有表的所有权限给jack这个用户 并允许jerry在任意一台电脑登录
grant all on day45.* to "jack"@"%" identified by "123";
授予day45数据库的emp表的所有权限给rose这个用户 并允许jerry在任意一台电脑登录
grant all on day45.emp to "rose"@"%" identified by "123";
授予day45数据库的emp表的name字段的查询权限给maria这个用户 并允许jerry在任意一台电脑登录
grant select(name) on day45.emp to "maria"@"%" identified by "123";

收回权限

REVOKE all privileges [column] on db.table from user@"host";

如何授权就如何收回 因为不同权限信息存到不同的表中
REVOKE all privileges on day45.emp from maria@"%";

立即刷新权限信息

flush privileges;

# 删除用户
drop user 用户名@主机
drop user maria@%

当你在云服务器部署了 mysql环境时 你的程序无法直接连接到服务器 需要授予在任意一台电脑登录的权限
grant all on *.* to "jerry"@"%" identified by "123" with grant option;

posted @ 2018-11-23 20:04  msjaxuexi  阅读(114)  评论(0编辑  收藏  举报