ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
软件:mysql
关键词:启动、退出、初始化、获得初始密码、修改密码、使用新密码登录、密码登录出问题
结果:成功初始化修改密码后进入mysql
问题:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
如果出现以下错误:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
就需要初始化mysql:
C:\WINDOWS\system32>mysqld --initialize -user=mysql –console
如果出现这种错误:
2021-02-25T02:39:03.354017Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2021-02-25T02:39:03.354480Z 0 [ERROR] Aborting
就需要在MySQL文件夹目录下的data中的数据全部清空,清空后再次执行上述命令,即:
C:\WINDOWS\system32>mysqld --initialize -user=mysql –console
成功后获得新密码:
2021-02-25T02:39:55.743996Z 1 [Note] A temporary password is generated for root@localhost: ,Xr&pA:=f89H(随机生成)
现在修改密码:
mysql> set password = password(‘123456’);(设置自己的密码)
会出现以下命令:
Query OK, 0 rows affected, 1 warning (0.00 sec)
为判断密码是否修改成功,先退出MySQL,退出方法如下:
mysql> QUIT;
退出后再次重新启动MySQL,启动命令如下:
C:\WINDOWS\system32>net start mysql
启动后登录MySQL,命令如下:
C:\WINDOWS\system32>mysql -uroot -p
出现密码输入提示:
Enter password:
键入你的新密码,如123456:
Enter password: ******
显示如下命令即表示你已经修改密码成功:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright © 2000, 2019, 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.