Mysql connection database error: 1045 - Access denied for user 'root'@'localhost' (using password: YES)

When connecting to the database or connecting to the database in Navicat, the error message is: 1045 - Access denied for user 'root'@'localhost' (using password: YES)

Connection to the database error problem

1. Error message

1. Terminal connection error

# 终端连接报错提示信息
1045 - Access denied for user 'root'@'localhost' (using password:YES)

  1. Navicat connection error

2. Solution:

  1. run cmd as administrator;

2.cd to the bin directory under mysql;

C:\Program Files\MySQL\MySQL Server 5.5\bin

cmd

3. Stop mysql service

# window环境 停止mysql服务命令
net stop mysql

# 虚拟机centos环境 停止mysql服务命令
service mysqld stop

4.mysql permission shielding

# window环境 停止mysql服务命令
mysqld --skip-grant-table

# 虚拟机centos环境 停止mysql服务命令
mysqld_safe --skip-grant-table

5. Re-open the terminal ( shortcut key: win+r )

mysql -u root mysql

6. Reset mysql password

# 重置root用户密码为:test132456
UPDATE user SET Password=PASSWORD(‘test123456’) where USER=‘root’;

Password reset successful

7. Update the database

# 更新命令
FLUSH PRIVILEGES;

# 删除空user命名
delete from user where USER='';

3. Connect to the database

  1. terminal connection database

# 连接数据库
mysql -u root -p

# 输输入重置的密码test123456
test123456
  1. Navicat connects to the database

Guess you like

Origin blog.csdn.net/qq_28807911/article/details/129304572