MySQL--创建用户

========================================================================

CREATE USER语法

CREATE USER 'username'@'hostname' IDENTIFIED BY 'password'; 

 

GRANT USER语法


GRANT
priv_type ON object_type TO 'username'@'hostname' IDENTIFIED BY [PASSWORD] 'password' [WITH GRANT OPTION]

 

PASSWORD用法:


[
PASSWORD]是可选参数,IDENTIFIED BY PASSWORD 后跟的是加密后的密码,IDENTIFIED BY 后跟的是未加密的密码 GRANT USAGE ON *.* TO 'cx'@'%' IDENTIFIED BY PASSWORD '*67CF1635475C64DE1C9608FEEE1AD307C4C2BC2F'; 和 GRANT USAGE ON *.* TO 'cx'@'%' IDENTIFIED BY 'abc@123.com'; 上面两条SQL效果一样,但推荐使用第一种方式,第二种方式的明文密码会被记录到binlog中,存在安全风险。

 

WITH GRANT OPTION


WITH
GRANT OPTION 允许用户将自身拥有的权限授予他人。
The WITH GRANT OPTION clause gives the user the ability to give to other users any privileges the user has at the specified privilege level.

 

通配符


对于hostname,可以使用%和_两种通配符,如: GRANT ALL PRIVILEGES ON *.* TO 'gga1'@'%.mysql.com' IDENTIFIED BY '123@456' WITH GRANT OPTION; %表示通配0到N个字符 _表示通配1个字符

 

用户过期


#设置用户过期时间为60天过期
ALTER USER 'gga'@'localhost' PASSWORD EXPIRE INTERVAL 60 DAY;

========================================================================

用户权限

在MySQL中,有5种控制数据访问的权限,12种控制数据结构的权限,11种管理数据库系统的权限

posted @ 2019-02-15 19:34  TeyGao  阅读(169)  评论(0编辑  收藏  举报