I also encountered this problem this morning and struggled with it for a long time. You can refer to the following methods:
Stop the MySQL service mysql.server stop
Back up the /usr/local/var/mysql/ folder, and then delete everything in the folder
Execute the mysqld --initialize command, and a temporary password will be generated, similar to A temporary password is generated for root@localhost: k+njnwJML78a
Restart the MySQL service mysql.server start. If unsuccessful, you can shut down and restart, and then restart the MySQL service
You should be able to log in with this password now
Thank you very much for the inspiration provided by @Charlesshen’s answer. After mysql version 5.7, the initial password of root is no longer empty/root, etc. It has become a random temporary password. During installation, online tutorials all prompt It said it would pop up, but I didn't see it, so I carefully looked at the installation method of the tar package and found that this installation is feasible. Then the second step folder of @Charlesshen above should be /usr/local/mysql/ data, directly sudo rm -rf ./data. Then continue to execute and a temporary password will appear.
I also encountered this problem this morning and struggled with it for a long time. You can refer to the following methods:
Stop the MySQL service mysql.server stop
Back up the /usr/local/var/mysql/ folder, and then delete everything in the folder
Execute the mysqld --initialize command, and a temporary password will be generated, similar to A temporary password is generated for root@localhost: k+njnwJML78a
Restart the MySQL service mysql.server start. If unsuccessful, you can shut down and restart, and then restart the MySQL service
You should be able to log in with this password now
Thank you very much for the inspiration provided by @Charlesshen’s answer. After mysql version 5.7, the initial password of root is no longer empty/root, etc. It has become a random temporary password. During installation, online tutorials all prompt It said it would pop up, but I didn't see it, so I carefully looked at the installation method of the tar package and found that this installation is feasible. Then the second step folder of @Charlesshen above should be /usr/local/mysql/ data, directly sudo rm -rf ./data. Then continue to execute and a temporary password will appear.
I switched to Mariadb because of this problem