操作系统 : Red Hat Enterprise Linux Server> 数据库版本: 5.7.18 MySQL Community Server (GPL)
忘记密码,输入错误的密码时遇到下面错误信息:
[iyunv@mytestlnx02 ~]# mysql -u root -pEnter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)[iyunv@mytestlnx02 ~]# 检查MySQL服务是否启动,如果启动,关闭MySQL服务
然后启动MySQL,进入MySQL后,修改root密码,操作过程中遇到ERROR 1054 (42S22): Unknown column 'password' in 'field list',查了一下user表的表结构,发现原来MySQL 5.7下,user表已经没有Password字段。加密后的用户密码存储于authentication_string字段。具体操作过程如下所示:
[iyunv@mytestlnx02 ~]# service mysqld startStarting mysqld: [ OK ][iyunv@mytestlnx02 ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection>Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A Database changedmysql> update user set password=PASSWORD('Kd8k&dfdl023') -> where user='root';ERROR 1054 (42S22): Unknown column 'password' in 'field list'mysql> update mysql.user set authentication_string=password('Kd8k&dfdl023') 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) mysql> exit
在my.cnf文件中,把刚才加入的那一行“skip-grant-tables”注释或删除掉。 然后重启MySQL服务后需要执行命令set password=password('newpassword');后,问题搞定。
[iyunv@mytestlnx02 ~]# service mysqld startStarting mysqld: [ OK ][iyunv@mytestlnx02 ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection>Server version: 5.7.18 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> set password=password('Kd8k&dfdl023');Query OK, 0 rows affected, 1 warning (0.00 sec) 后面查询了一下相关资料,发现MySQL 5.7在安全方面有下一些新特性(参考MySQL 5.7版本新特性连载(三))