数据库基础操作:DCL 控制数据库

  • A+
所属分类:数据语言

DCL(Data Control Language)控制数据库:数据控制语言,用来定义访问权限和安全级别。非DBA,一般用不到

 

创建用户

语法:

CREATE USER 用户名@地址 IDENTIFIED BY '密码';

# user1用户只能在localhost这个IP登录mysql服务器
CREATE USER user1@localhost IDENTIFIED BY ‘123;

# user2用户可以在任何电脑上登录mysql服务器
CREATE USER user2@’%’ IDENTIFIED BY ‘123’;   

 

给用户授权

语法:

GRANT 权限1, … , 权限n ON 数据库.* TO 用户名;

GRANT CREATE,ALTER,DROP,INSERT,UPDATE,DELETE,SELECT ON mydb1.* TO user1@localhost;

GRANT ALL ON mydb1.* TO user2@localhost;

 

 

撤销授权

语法:

REVOKE权限1, … , 权限n ON 数据库.* FORM 用户名;

REVOKE CREATE,ALTER,DROP ON mydb1.* FROM user1@localhost;

 

查看用户授权

语法:

SHOW GRANTS FOR 用户名

SHOW GRANTS FOR user1@localhost;

 

删除用户

语法:

DROP USER 用户名;

DROP USER user1@localhost;

 

修改用户密码

语法:

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;
  • 扫扫关注公众号
  • weinxin
  • 扫扫体验小程序
  • weinxin
亦枫

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: