SQL(四) DCL数据库用户与权限

1.DCL(数据控制语言)

  • DDL
  • DML数据操作语言
  • DCL数据控制语言
# 删除用户
drop user if exists 'user_name'@'localhost';

# 创建数据库用户
create user 'user_name'@'localhost' identified by 'mima.123456';
             创建的用户名   连接方式('localhost'本地,'10.7.174.90:1'局域网,'10.7.174.%'此前缀的任意局域网,'%'任意连接方式)   密码要强密码,包括英文数字特殊符号

# 修改密码
alter user 'user_name'@'localhost'identified by 'mima.654321';

# 授予权限。
#连接方式不同,即便名字相同也不算是一样的
# hrs库的所有select查询权限,点后面可以放表名、视图名,更精确
grant select on hrs.* to 'user_name'@'localhost';
# insert权限
grant insert on hrs.* to 'user_name'@'localhost'; 
# 多个权限
grant select,insert,delete,update on hrs.* to 'user_name'@'localhost';
# hrs库的所有权限
grant all privileges on hrs.* to 'user_name'@'localhost';
# 所有库的所有权限,但跟root管理员还是有区别,没有权限授予权限
grant all privileges on *.* to 'user_name'@'localhost';
# 想当于root管理员
grant all privileges on *.* to 'user_name'@'localhost' with grant option;

# 收回权限
# 授权与收权要对应,hrs.* -> hrs.* , *.* -> *.*
revoke insert on hrs.* from 'user_name'@'localhost';
revoke all privileges on *.* from 'user_name'@'localhost';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值