sunmingtao / sample-code

3 stars 4 forks source link

Access denied for user 'root@localhost' (using password:NO) #295

Closed sunmingtao closed 2 years ago

sunmingtao commented 2 years ago

Download mysql5.7 zip Unzip Run mysqld --initialize Start the server mysqld --console In another command line, attempt to access the server mysql -u root -p

Tried both password root and no password. Not working

sunmingtao commented 2 years ago

Restart the server with command mysqld --skip-grant-table --console In another command line window

mysql
use mysql
UPDATE user SET `authentication_string` = PASSWORD('root') WHERE `User` = 'root';

In the first command line window, start mysql normally by mysqld --console In the second command line window

mysql -u root -p
(Enter password: root)
 SET PASSWORD = PASSWORD('root');

This step is necessary if getting the following error when attempting to connect to the server through MySql Workbench.

you must reset your password using alter user statement before executing this statement

sunmingtao commented 2 years ago

The problem might not have occurred if the db was initialized using the command mysqld --initialize-insecure https://github.com/sunmingtao/sample-code/issues/123