SQL-DCL-数据控制语言

一、 DCL-管理用户

二、DCL-权限控制

sql 复制代码
一、 DCL-管理用户,主要是DBA数据库管理员使用,开发使用较少
# 1、查询用户
use mysql;
show tables;
desc user;
select * from user;
# host为主机地址, 主机地址和用户名确定唯一性

# 2、创建用户
create user 'itcast'@'localhost' identified by '123456'; # 用户itcast在localhost本机,密码123456,此时权限不完全
create user 'user1'@'%' identified by '123456';# %代表任意主机

# 3、修改用户密码
alter user 'user1'@'%' identified with  mysql_native_password by '654321';# 修改本地用户

# 4、删除用户
drop user 'itcast'@'localhost';



二、DCL-权限控制
# 查询权限
show  grants for 'user1'@'%' ;
# GRANT USAGE ON *.* TO `itcast`@`localhost`仅仅可以连接登陆mysql
# 授予权限
grant  alter,drop on itcast.* to 'user1'@'%' ;
grant  all on itcast.* to 'user1'@'%' ;# 授权数据库的全部表
grant  all on *.* to 'user1'@'%' ;# 授权全部数据库

# 撤销权限
revoke all on itcast.* from 'user1'@'%' ;
revoke alter on itcast.* from 'user1'@'%' ;
sql 复制代码
### cmd


C:\Users\hym>mysql -u user1 -p
Enter password: ******
ERROR 1045 (28000): Access denied for user 'user1'@'localhost' (using password: YES)

C:\Users\hym>mysql -u user1 -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.39 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+
2 rows in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| itcast             |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
相关推荐
后端优选官43 分钟前
上海Agent开发公司:企业级智能体软件的技术架构与落地评估
数据库·人工智能·架构·软件开发·开发经验·上海
JustNow_Man43 分钟前
`openspec/config.yaml` 解析与生效机制
数据库
Databend1 小时前
用 QUALIFY 写出更清晰的窗口函数 SQL
数据库·sql·数据分析
数智化管理手记1 小时前
应收应付资金占用过高怎么办?应收应付搭配账龄分析怎么做
大数据·网络·数据库·人工智能·数据挖掘
用户71333585156241 小时前
MySQL - EXPLAIN 执行计划
数据库
这就是佬们吗1 小时前
Python入门③-运算符、条件与循环
开发语言·数据库·vscode·python·pycharm·编辑器
wending-Y1 小时前
Flink 滑动窗口作业 TaskManager RocksDB 状态膨胀 Bug 分析
java·前端·数据库
小大宇1 小时前
mongoDB dump技巧
数据库·mongodb
huijingjituan1 小时前
三方聊天软件工具定制开发|打造企业级智能通讯平台
数据库·安全·阿里云·实时互动·腾讯云
zyplayer-doc1 小时前
研发接口文档怎么长期维护:zyplayer-doc把API、Markdown和变更记录放进同一个知识库
大数据·数据库·人工智能·笔记·pdf·ocr