Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错

时间:2022-07-11 09:03:31

MySQL 连接错误,使用Navicat连接MySQL出现错误:1045 Access denied for user 'root'@'localhost' (using password: YES)

Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错

解决方案:

1.编辑mysql配置文件my.ini

在mysql的安装目录下

Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错

,在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql

[mysqld]
#作用是跳过登录的验证
#skip-grant-tables
port =
basedir=C:\\softwaretool\\mysql-5.7.-winx64
datadir=C:\\softwaretool\\mysql-5.7.-winx64\\data
max_connections=
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 20M
[mysql]
default-character-set=utf8

2.重启mysql

在计算机-管理-服务里面找到MySQL的服务,如图

Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错

这时候在cmd里面输入mysql -u root -p就可以不用密码登录了,出现 password:的时候直接回车可以进入,不会出现ERROR 1045 (28000),但很多操作都会受限制,因为没有grant权限。

Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错

3.进入mysql数据库,给root用户设置密码

mysql> use mysql;
mysql> update mysql.user set authentication_string=password('密码') where user='root' ;

Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错

4.刷新数据库,并退出

mysql> flush privileges;
mysql> quit;

Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错

5.修改my.ini文件

改好之后,再修改一下my.ini这个文件,把我们刚才加入的 "skip-grant-tables"这行删除,保存退出再重启mysql服务,再重新用Navicat连接就可以了。

[mysqld]
#作用是跳过登录的验证
#skip-grant-tables
port =
basedir=C:\\softwaretool\\mysql-5.7.-winx64
datadir=C:\\softwaretool\\mysql-5.7.-winx64\\data
max_connections=
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 20M
[mysql]
default-character-set=utf8

Mysql相关问题-----1045 Access denied for user 'root'@'localhost' (using password: YES)报错