个人主页: 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的功能

`DCL-管理用户``1.查询用户``2.创建用户``3.修改用户密码``4.删除用户`

SQL

DCL

DCL (Data Control Language):数据控制语言,用来管理数据库 用户、 控制数据库的 访问权限。

1.有哪些用户可以访问2.用户可以操作哪些数据库

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

create user 'Aileen'@'localhost' identified by '123456';

但是上表显示我们新创建的用户Ailleen没有访问权限。下面让我们通过命令行去访问

通过命令行查询我们可以发现,我们只能查询到一个数据库,而刚刚在root里面我们可以看到很多的数据库,为什么会出现这种情况呢?

原因:刚刚我们只是创建了Aileen这个数据库,他可以访问mysql但它没有访问其它数据库的权限,当前只是创建了Aileen这个用户,还没有给他分配权限。

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

create user 'Betty'@'%' identified by '123456';

3.修改用户密码

Created with Raphaël 2.3.0

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

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

alter user 'Betty'@'%' identified with mysql_native_password by '1234';

4.删除用户

Created with Raphaël 2.3.0

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

删除 Aileen@localhost 用户

drop user 'Aileen'@'localhost' ;

⚠️注意:

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

参考链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: