Navicat连接MySQL-出现1045无法连接问题
问题背景:安装完MySQL和Navicat后,在命令行终端输入密码,总是报错;但可以无密码进入MySQL命令行。与此同时,用Navicat连接MySQL时,输入密码,显示无法连接【前提:密码输入正确】
win+R,命令行终端报错代码如下:
C:\Users\lenovo>mysql -u root -p 111111
Enter password: ******
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
C:\Users\lenovo>mysql -u root -p
Enter password: ******
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
C:\Users\lenovo>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 9.3.0 MySQL Community Server - GPL
Copyright © 2000, 2025, Oracle and/or its affiliates.
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.
mysql>
解决办法:
- 修改 MySQL 用户密码
首先,确保 ‘root’ 用户有一个强密码,并且这个密码在 Navicat 中也被正确输入。
登录 MySQL 命令行(无需密码):
mysql -u root
2.更新 ‘root’ 用户的密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
将 new_password 替换为你想要设置的新密码。
3.刷新权限,使更改生效:
FLUSH PRIVILEGES;
4.退出 MySQL:
exit;
5.输入密码,重新连接,就能连上了