DCL-管理用户
-
Data Control Language:用来管理数据库用户、控制数据库的访问权限
-
语法
-
1.查询用户 user mysql; select * from user; 2.创建用户 create user '用户名'@'主机名' indentifide by '密码'; 3.修改用户密码 alter user '用户名'@'主机名' identifide with mysql_native_password by '新密码'; 4.删除用户 drop user '用户名'@'主机名'; -- 1.创建用户 itcast只能够在当前主机Localhost访问,密码123456 create user 'itcast'@'localhost' identified by '123456'; -- 2.创建用户 heima ,可以在任意主机访问该数据库,密码123456 create user 'heima'@'%' identified by '123456'; -- 3.修改用户 heima 的访问密码为 1234 alter user 'heima'@'%' identified with mysql_native_password by '1234'; -- 4.删除itcast@localhost用户 drop user 'itcast'@'localhost';
-
DCL-权限控制
-
注意:
- 多个权限之间,使用逗号分隔
- 授权时,数据库名和表名可以使用* 进行通配,代表所有
-
常用权限
-
语法
-
1.查询权限 show grants for '用户名'@'主机名'; 2.授予权限 grant 权限列表 on 数据库名.表名 to '用户名'@'主机名'; 3.撤销权限 revoke 权限列表 on 数据库名.表名 from '用户名'@'主机名'; -- 查询权限 show grants for 'heima'@'%'; -- 授予权限 grant all on itcast.* to 'heima'@'%'; -- 撤销权限 revoke all on itcast.* from 'heima'@'%';
-