解决这个错误。
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
-
Stop mysql: systemctl stop mysqld -
Set the mySQL environment option systemctl set-environment MYSQLD_OPTS="–skip-grant-tables" -
Start mysql usig the options you just set systemctl start mysqld -
Login as root mysql -u root -
Update the root user password with these mysql commands mysql> UPDATE mysql.user SET authentication_string = PASSWORD(‘MyNewPassword’) -> WHERE User = ‘root’ AND Host = ‘localhost’; mysql> FLUSH PRIVILEGES; mysql> quit
*** Edit *** As mentioned my shokulei in the comments, for 5.7.6 and later, you should use mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘MyNewPass’; Or you’ll get a warning
-
Stop mysql systemctl stop mysqld -
Unset the mySQL envitroment option so it starts normally next time systemctl unset-environment MYSQLD_OPTS -
Start mysql normally: systemctl start mysqld
Try to login using your new password: 9. mysql -u root -p
在以上的操作过程中会遇到以下问题 ERROR 1396 (HY000): Operation CREATE USER failed for ‘root’@‘localhost’
1 create user ‘root’@‘localhost’ identified by ‘123456’;
2 flush privileges;
3 create user ‘root’@‘localhost’ identified by ‘123456’;
4 如果再次报错 drop user ‘root’@‘localhost’;
5再次创建 create user ‘root’@‘localhost’ identified by ‘123456’;
|