0


【MySQL】学习如何使用DCL进行用户管理

](https://img-blog.csdnimg.cn/21dd41dce63a4f2da07b9d879ad0120b.png#pic_center)

🌈个人主页: Aileen_0v0
🔥热门专栏: 华为鸿蒙系统学习|计算机网络|数据结构与算法
💫个人格言:“没有罗马,那就自己创造罗马~”

#mermaid-svg-JwFD16F1Kh0fle0X {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-JwFD16F1Kh0fle0X .error-icon{fill:#552222;}#mermaid-svg-JwFD16F1Kh0fle0X .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-JwFD16F1Kh0fle0X .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-JwFD16F1Kh0fle0X .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-JwFD16F1Kh0fle0X .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-JwFD16F1Kh0fle0X .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-JwFD16F1Kh0fle0X .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-JwFD16F1Kh0fle0X .marker{fill:#333333;stroke:#333333;}#mermaid-svg-JwFD16F1Kh0fle0X .marker.cross{stroke:#333333;}#mermaid-svg-JwFD16F1Kh0fle0X svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-JwFD16F1Kh0fle0X .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-JwFD16F1Kh0fle0X .cluster-label text{fill:#333;}#mermaid-svg-JwFD16F1Kh0fle0X .cluster-label span{color:#333;}#mermaid-svg-JwFD16F1Kh0fle0X .label text,#mermaid-svg-JwFD16F1Kh0fle0X span{fill:#333;color:#333;}#mermaid-svg-JwFD16F1Kh0fle0X .node rect,#mermaid-svg-JwFD16F1Kh0fle0X .node circle,#mermaid-svg-JwFD16F1Kh0fle0X .node ellipse,#mermaid-svg-JwFD16F1Kh0fle0X .node polygon,#mermaid-svg-JwFD16F1Kh0fle0X .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-JwFD16F1Kh0fle0X .node .label{text-align:center;}#mermaid-svg-JwFD16F1Kh0fle0X .node.clickable{cursor:pointer;}#mermaid-svg-JwFD16F1Kh0fle0X .arrowheadPath{fill:#333333;}#mermaid-svg-JwFD16F1Kh0fle0X .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-JwFD16F1Kh0fle0X .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-JwFD16F1Kh0fle0X .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-JwFD16F1Kh0fle0X .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-JwFD16F1Kh0fle0X .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-JwFD16F1Kh0fle0X .cluster text{fill:#333;}#mermaid-svg-JwFD16F1Kh0fle0X .cluster span{color:#333;}#mermaid-svg-JwFD16F1Kh0fle0X div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-JwFD16F1Kh0fle0X :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}
I have found that if you love life, life will love you back.

文章目录

SQL

DCL
  • DCL (Data Control Language):数据控制语言,用来管理数据库 用户、 控制数据库的 访问权限。- 1.有哪些用户可以访问- 2.用户可以操作哪些数据库

DCL的功能


DCL-管理用户

1.查询用户
Created with Raphaël 2.3.0 

 use mysql; 

 ---------------- 

 select * from user; 

⚠️用户名和主机地址才能完整的定位一个MySQL的用户
在这里插入图片描述


2.创建用户
Created with Raphaël 2.3.0 

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

创建用户 Aileen , 只能够在当前主机localhost访问 , 密码:123456

createuser'Aileen'@'localhost' identified by'123456';

在这里插入图片描述
但是上表显示我们新创建的用户Ailleen没有访问权限。下面让我们通过命令行去访问👇
在这里插入图片描述
在这里插入图片描述
通过命令行查询我们可以发现,我们只能查询到一个数据库,而刚刚在root里面我们可以看到很多的数据库,为什么会出现这种情况呢?原因:刚刚我们只是创建了Aileen这个数据库,他可以访问mysql但它没有访问其它数据库的权限,当前只是创建了Aileen这个用户,还没有给他分配权限。


创建用户 Betty , 可以在任意主机访问该数据库,密码123456;

createuser'Betty'@'%' identified  by'123456';

3.修改用户密码
Created with Raphaël 2.3.0 

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

修改用户 Betty 的访问密码为 1234 ;

alteruser'Betty'@'%' identified  with mysql_native_password by'1234';

在这里插入图片描述


4.删除用户
Created with Raphaël 2.3.0 

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

删除 Aileen@localhost 用户

dropuser'Aileen'@'localhost';

在这里插入图片描述

  • ⚠️注意: - 主机名可以使用%通配 (写了%表示任意主机都可以访问MySQL服务器)- 这类sql开发人员操作较少,主要是DBA(Database Administrator 数据库管理员)使用。

](https://img-blog.csdnimg.cn/0ee6c4ec414740b0a0404c5161cdadc7.gif#pic_center)

](https://img-blog.csdnimg.cn/cc002cbd5c414c5393e19c5e0a0dbf20.gif#pic_center#pic_center)

标签: mysql 学习 adb

本文转载自: https://blog.csdn.net/Aileenvov/article/details/136043364
版权归原作者 Aileen_0v0 所有, 如有侵权,请联系我们删除。

“【MySQL】学习如何使用DCL进行用户管理”的评论:

还没有评论