mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)

05-13 1172阅读

连接数据库或者在Navicat连接数据库,报错信息为:1045 - Access denied for user 'root'@'localhost' (using password:YES)

连接数据库报错问题

一、报错问题提示信息

1.终端连接报错
# 终端连接报错提示信息
1045 - Access denied for user 'root'@'localhost' (using password:YES)
  1. Navicat连接报错
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)

二、解决方法:

  1. 以管理员身份运行cmd;
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
2.cd到mysql下的bin目录;
C:\Program Files\MySQL\MySQL Server 5.5\bin
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
cmd
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
3.停止mysql服务
# window环境 停止mysql服务命令
net stop mysql
# 虚拟机centos环境 停止mysql服务命令
service mysqld stop
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
4.mysql权限屏蔽
# window环境 停止mysql服务命令
mysqld --skip-grant-table
# 虚拟机centos环境 停止mysql服务命令
mysqld_safe --skip-grant-table
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
5.重新打开终端(快捷键:win+r)
mysql -u root mysql
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
6.重置mysql密码
# 重置root用户密码为:test132456
UPDATE user SET Password=PASSWORD('test123456') where USER ='root';

重置密码成功

mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
7.更新数据库
# 更新命令
FLUSH PRIVILEGES;
# 删除空user命名
delete from user where USER='';
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)

三、连接数据库

  1. 终端连接数据库
# 连接数据库
mysql -u root -p
# 输输入重置的密码test123456
test123456
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
  1. Navicat连接数据库
mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)mysql连接数据库报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password:YES)
VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]