Problem Description
When I woke up, the database service failed, the password was entered correctly, but I could not log in. I was going to reset the database password, and the steps were in progress.
mysqld --initialize --console
Initialize the database password, but still cannot enter the database and report an error after entering the password
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
problem solved
1. Shut down the database service:
net stop mysql
2. Open cmd with administrator privileges ( note that it must be administrator privileges )
in the terminal, go to the bin file directory of your MySQL installation directory to log in to
MySQL 8.x without permission :
mysqld --console --skip-grant-tables --shared-memory
MySQL 5.x login without permission :
mysqld --skip-grant-tables
3. Create a new terminal window (run as an administrator)
(the password of -p is blank for password-free login)
mysql -u root -p
After successful login, execute:
alter user 'root'@'localhost' identified by '新的密码';
3.1 There may be a problem of insufficient permissions here:
ERROR 1290 (HY000): The MySQL server is running with the
–skip-grant-tables option so it cannot execute this statement
Refresh permissions to solve:
flush privileges;
After the refresh is completed, continue to execute the command to modify the new password
alter user 'root'@'localhost' identified by '新的密码';
4. Close all terminal windows and restart the MySQL service:
net start mysql
5. Log in to MySQL
mysql -uroot -p 刚设置的密码