[Database connection failure] The database connection error 1045-Access denied for user'root'@'localhost' (using password: YES/NO) is reported in Navicat

Recently, there was an error when testing the connection pool with native spring, so I thought about taking a step back and directly using the classic jdbc (only mysql-connector-java), but I still reported the error-then I tested it in IDEA, and finally located the bug. Database connection problem.
 
To make a long story short, I think the macBigSur and mysql8.0 updates have caused many root user permissions and parameter default values. Because these problems have only recently been exposed, there are few feasible solutions on the Internet, and many detours have been taken.
 
It took two days for me to realize that the database connection failures in Navicat and IDEA are two separate errors . This article addresses the former . let's go.

 
 

1045 - Access denied for user ‘root’@‘localhost’ (using password: YES/NO)

Literal translation: error code 1045-denied access to user'root' (whether the password is filled in: YES/NO)

Insert picture description here

 

 
 

Solution One-Directly use Navicat's graphical interface to operate

Insert picture description here

 
 

Option Two-Use the command line to temporarily skip password verification

1.关闭mysql服务
  >>> sudo /usr/local/mysql/support-files/mysql.server stop
  
2.进入到bin文件夹
  >>> cd /usr/local/mysql/bin/

3.获取超级管理员权限
  >>> sudo su

4.禁止身份验证
  >>> ./mysqld_safe --skip-grant-tables &

5.此时mysql服务自动重启,这次无需密码即可成功连接,自然不会报错

 
 

Solution Three-Use the command line to modify the password

6.接着上面的操作。进入mysql客户端
  >>> sudo /usr/local/mysql/bin/mysql -u root -p

7.修改用户root的密码
  >>> flush privileges;
  >>> SET PASSWORD FOR root@localhost = '123456';

 
 
 
 
 
 
 
 

Finally, add a few command lines to copy and paste (mac)

sudo /usr/local/mysql/support-files/mysql.server start			// mysql数据库服务开启
sudo /usr/local/mysql/support-files/mysql.server stop			// mysql数据库服务关闭
sudo /usr/local/mysql/support-files/mysql.server restart			// mysql数据库服务重启

sudo /usr/local/mysql/bin/mysql -u root -p						// 开启mysql客户端(>>>就可以写sql语句啦)

Guess you like

Origin blog.csdn.net/m0_46202073/article/details/113833955