DCL(Data Control Language)
数据控制语言,用来定义访问权限和安全级别。
1.创建用户
语法:
CREATE USER 用户名@地址 IDENTIFIED BY '密码';
例:
create user testuser1@localhost identified by '111';
2.给用户授权
语法:
GRANT 权限1, … , 权限n ON 数据库.* TO 用户名;
例:
grant create,alter,drop,insert,update,delete,select on test999.* to testuser1@localhost;
3.撤销授权
语法:
REVOKE权限1, … , 权限n ON 数据库.* FORM 用户名;
例:
revoke create,alter,drop on test999.* to testuser1@localhost;
4.查看用户权限
语法:
SHOW GRANTS FOR 用户名;
例:
show grants for testuser1@localhost;
5.删除用户
语法:
DROP USER 用户名;
例:
drop user testuser1@localhost;
6.修改用户密码
语法:
USE mysql;
UPDATE USER SET PASSWORD=PASSWORD(‘密码’) WHERE User=’用户名’ and Host=’IP’;
FLUSH PRIVILEGES;
例:
update user set password=password('1234') where user='user2' and host=’localhost’;
flush privileges;