max_user_connections: 0
plugin: mysql_native_password
authentication_string: *D5F86FA8F536F9E81C12E8A993EF5292A90259FB
password_expired: Y
password_last_changed: 2015-08-18 11:11:39
password_lifetime: NULL
account_locked: N
1 row in set (0.00 sec)
只有一个root帐号,并且密码已经过期了。
在这里修改密码的时候,要考虑到pasword_expied,设置成N,才可以用。
修改密码:
mysql> update mysql.user set authentication_string=password(‘redhat’), password_expired=’N’ where user=’root’;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
可能感觉这个方法有点怪异,为什么不直接set password=password();
看一下
mysql> set password=password(‘123’);
ERROR 1131 (42000): You are using MySQL as an anonymous user and anonymous users are not allowed to change passwords
答案是不可以,因为mysql.user表已经没有这个字段了。
修改完成之后,用root登录。
mysql> select current_user();
+—————-+
| current_user() |
+—————-+
| root@localhost |
+—————-+
1 row in set (0.00 sec)
登录ok。