MySQL8.0ログイン-一時パスワードの表示/変更


一、問題の説明
次のコードを実行します.
mysql -uroot

実行結果は次のとおりです.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

間違いの原因は秘密の間違いだ.初めてMysqlを起動する時システムは自動的に臨時の秘密を生成して、臨時のパスワードを探し当てて正常に上陸することができます
二、解決方法
(1)仮秘密の表示
1、ファイルディレクトリを/var/logに切り替える
cd /var/log

2、mysqldを表示する.logファイル
more mysqld.log

結果は次のとおりです.
2020-07-16T17:07:59.769774Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (my
sqld 8.0.21) initializing of server in progress as process 9857
2020-07-16T17:07:59.776926Z 1 [System] [MY-013576] [InnoDB] InnoDB initializatio
n has started.
2020-07-16T17:08:00.567970Z 1 [System] [MY-013577] [InnoDB] InnoDB initializatio
n has ended.
2020-07-16T17:08:02.500261Z 6 [Note] [MY-010454] [Server] A temporary password i
s generated for root@localhost:YbitKorHK3--More--(21%)

YbitKorHK 3は、mysqlにログインするrootユーザーに次のコードを入力します.
mysql -uroot -p

結果は次のとおりです.
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21

Copyright (c) 2000, 2020, 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.

Enter password:後で一時秘密を入力するとログインできます.
(2)初期パスワードの変更
mysql rootユーザーにログインした後、次のコマンドを使用して初期パスワードを変更します.
alter  user 'root'@'localhost' identified by "mima@123";