数据库: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';

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

相关推荐
l1t29 分钟前
DeepSeek总结的有符号、无符号、未对齐:从汇编到 SQL 的教训
汇编·数据库·sql
夜雪一千35 分钟前
MySQL 如何提高查询速度:从索引、SQL、表结构到实战调优
android·sql·mysql
麦壳饼1 小时前
SonnetDB SQL Cookbook:常用查询模式速查
数据库·sonnetdb
for_ever_love__1 小时前
LangChain Text-to-SQL:让不会写 SQL 的人查数据库
数据库·sql·langchain·大模型·agent·rag·问答
梦想不只是梦与想2 小时前
SQLAlchemy:查询与操作 (三)
数据库·python·sqlalchemy
Aric_Jones2 小时前
WAL / CDC / 复制槽 /位点
数据库·oracle
草莓熊Lotso2 小时前
【C++ 基于微服务的即时通讯系统】基建三件套:gflags + gtest + spdlog 源码编译安装与实战入门
linux·网络·数据库·c++·微服务·log4j
bksczm2 小时前
Redis基础篇之初识分布式
数据库·redis·分布式
for_ever_love__2 小时前
MySQL 索引类型全解:B+Tree / Hash / R-Tree / 全文 的底层差异,以及一次性建对的选型表
数据库·mysql·b+树·唯一索引·全文索引·索引类型·索引分类
仍然.10 小时前
Redis---缓存
数据库·redis·缓存