DCL是数据控制语言,用来管理数据库用户,还有控制用户的访问权限

1.用户的查询
MySQL的用户信息存储在mysql数据库中,查询用户时,我们需要使用这个数据库。


后面,还有很多数据,因为篇幅的问题,就不过多赘述了。后面还有一个创建用户创建的时间


localhost说明只能在本地访问这个数据库


我们可以使用lcy用户登录我们的mysql

但是为什么lcy用户不能访问到其他数据库,这是因为,它没有访问其他数据库的权限
lcy用户只能在本地主机访问
那么怎么创建一个任何主机都可以访问的用户
下面我们创建一个cy用户,可以在任何主机访问数据库


当我们忘记用户的密码时,也可以修改用户的密码
语法



不需要这个用户也可以删除用户
语法



DCL 用户权力管理



我们创建一个lcy用户,和上面用户得创建一样,查询它的权限


可以看到lcy用户只有连接的权限。
那么我们怎么赋予权限呢
语法

在赋予权限之前,我们看一下它可以访问什么数据库

我们有一个test数据库,我们把它的所有权限给lcy用户

这时lcy表就有test。数据库的所有权限了

这个时候我们可以访问test数据库,查看看test数据库的所有表
我们也可以撤销授予的权限
语法


撤销权限后,查看到它没有权限。只能连接。
也可以通过查询数据库的方式查看

注意事项:
• 多个权限之间,使用逗号分隔
• 授权时, 数据库名和表名可以使用 * 进行通配,代表所有。
总结
