【MySQL 关于登陆密码过期设置】

安装的过程中有这样的一句话:

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,no other statement but 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

大概意思就是 一个随机的密码已经生成 可以在  '/root/.mysql_secret'. 中找到,第一次连接必须变更密码 且只能使用 'SET PASSWORD' 命令,在user 表中新增加了'password expired'  列,也就是密码过期

mysql> select 1;

ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

#提示必须现更改密码才能执行语句

mysql> set password=password('password2013');

Query OK, 0 rows affected (0.00 sec)

password expire default 子句就是用来设置mysql 账号的密码过期时间的(单位天)。

可以在MySQL的配置文件中设置一个默认值,这会使得所有MySQL用户的密码过期时间都为90天,MySQL会从启动时开始计算时间。my.cnf配置如下:

[mysqld]

default_password_lifetime=90

如果要设置密码永不过期的全局策略,可以这样:(注意这是默认值,配置文件中可以不声明)

[mysqld]

default_password_lifetime=0

在MySQL运行时可以使用超级权限修改此配置:

mysql> SET GLOBAL default_password_lifetime = 90;

Query OK, 0 rows affected (0.00 sec)

还可以使用ALTER USER命令为每个具体的用户账户单独设置特定的值,它会自动覆盖密码过期的全局策略。要注意ALTER USER语句的INTERVAL的单位是“天”。

ALTER USER ‘testuser'@‘localhost' PASSWORD EXPIRE INTERVAL 30 DAY;

禁用密码过期:

ALTER USER 'testuser'@'localhost' PASSWORD EXPIRE NEVER;

让用户使用默认的密码过期全局策略:

ALTER USER 'testuser'@'localhost' PASSWORD EXPIRE DEFAULT;

从MySQL 5.7.6版开始,还可以使用ALTER USER语句修改用户的密码:

mysql> ALTER USER USER() IDENTIFIED BY '637h1m27h36r33K';

Query OK, 0 rows affected (0.00 sec)

service mysql stop

bin/mysqld_safe --skip-grant-tables --skip-networking &

mysql

select user,host,authentication_string,password_expired from mysql.user;

update user set authentication_string=password('admin123') where user='root';

update user set password_expired='N' where user='root';

select user,host,authentication_string,password_expired from user;

filush privileges;

exit;

猜你喜欢

转载自gaojingsong.iteye.com/blog/2425110