[chb@centeros6 ~]$ mysqladmin -uroot -p root
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
碰到这种情况,安全启动mysql
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql
mysql> update user set authentication_string=PASSWORD('root') where user='root';
Query OK, 1 row affected, 1 warning (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
修改成功
重新启动mysql也成功
mysql登录后,提示修改密码
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set PASSWORD=Password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> alter user root@localhost PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
密码修改成功,密码也不提示过期了。