Mysql5.7 rootパスワードを取り戻す


システム環境CentOS 6.x+Mysql5.7
1.myを修正する.cnf
[mysqld]セグメントにskip-grant-tablesの構成を追加
2.mysqlを再起動する
# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

3.mysqlにログインする
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

4.パスワードの変更
注意mysql 5.7次の文を使用してパスワードを変更します.
mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

このエラーは度娘クエリを通過し、次の文を実行してからパスワードを変更する必要があります.
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

このエラーは、パスワードがセキュリティポリシーに合致しないことを示しています.デフォルトのパスワードの強度は少なくとも満たされています.大文字/小文字+アラビア数字+特殊文字で、長さは8ビット未満です.
mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

5.パスワードの再変更の有効化
mysql> alter user 'root'@'localhost' identified by '[email protected]';
Query OK, 0 rows affected (0.08 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

6.修正my.cnf skip-grant-tables構成を削除しmysqlを再起動して新しいパスワードでログインすればいい