数据库:SQL分类之DCL详解

1.管理用户

1.查询用户

use mysql ;

select * from user ;

2.创建用户

create user '用户名'@'主机名' identified by '密码' ;

例:

复制代码
//创建用户itcast ,只能够在当前主机local host访问,密码123456
create user 'itcast'@'localhost' identified by '123456';

//创建用户itcasts ,可以在任意主机访问该数据库,密码123456
create user 'itcasts'@'%' identified by '123456';// %代表任意
3.修改用户密码

alter user '用户名'@'主机名' identified with mysql_native_password by '新密码' ;

例:

复制代码
alter user 'itcast'@'local host' identified with mysql_native_password by '12345678' ;
4.删除用户

drop user '用户名'@'主机名 ;

例:

复制代码
drop user 'itcast'@'local host' ;

注意:

  • 主机名可以用%通配
  • 这类SQL开发人员操作的比较少,主要是DBA(Database Administrator 数据库管理员)使用。

2.权限控制

MySQL中定义了很多种权限,但是常用的就以下几种:

|----------------------|------------|
| 权限 | 说明 |
| all , all privileges | 所有权限 |
| select | 查询数据 |
| insert | 插入数据 |
| update | 修改数据 |
| delete | 删除数据 |
| alert | 修改表 |
| drop | 删除数据库/表/视图 |
| create | 创建数据库/表 |

1.查询权限

show grants for '用户名 '@'主机名' ;

例:

复制代码
show grants for 'itcast'@'local host';
2.授予权限

grant 权限列表 on 数据库名.表名 to '用户名'@'主机名' ;

例:

复制代码
grant all on itcast.* to 'itcast'@'local host';

3.撤销权限

revoke 权限列表 on 数据库名.表名 from '用户名'@'主机名' ;

例:

复制代码
revoke all on itcast.* from 'itcast'@'local host';

本期分享就到此结束啦,谢谢大家观看,我们下期再见!

相关推荐
+VX:Fegn08954 小时前
计算机毕业设计|基于springboot + vue蛋糕店管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·课程设计
哈__6 小时前
KES-Operator重塑Kubernetes环境下的KES数据库集群管理
数据库·kubernetes·operator·kes
IvorySQL7 小时前
IvorySQL 5.6 发布:PG 18.6 内核升级,沙盒即开即用
数据库·人工智能·postgresql
bbq粉刷匠8 小时前
触发器(下):事务与锁、binlog 一致性与替代方案
sql
CNSSIRD数据库8 小时前
中国企业环境信用数据库2003-2026
大数据·数据库·数据分析·论文笔记
fd32009 小时前
达梦数据库更新统计信息后仍走旧执行计划解决方案
数据库
华章酱9 小时前
MySQL幻读是怎么出现的
数据库·mysql·幻读
浅念-10 小时前
Redis基础详解:单线程模型、String与Hash数据结构
服务器·数据库·redis·sql·mysql·nosql数据库·nosql
updayday85410 小时前
离职域账号状态变更与Ping64操作记录核对
大数据·网络·数据库·安全·智能路由器