gpt4 book ai didi

java - 错误: Client does not support authentication protocol requested by server; consider upgrading MySQL client

转载 作者:行者123 更新时间:2023-11-29 15:50:32 25 4
gpt4 key购买 nike

在执行 JDBC 程序时,连接数据库时出现以下错误:

Exception in thread "main" 
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Client does
not support authentication protocol requested by server; consider upgrading
MySQL client
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:921)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at main.java.MyFirstJdbcProgram.readDataBase(MyFirstJdbcProgram.java:23)
at main.java.Main.main(Main.java:6)

当我研究这个时,我知道下面的错误是因为我需要向用户授予权限,所以按照

  1. mysql -u root -p
  2. 然后输入密码
  3. 然后我就跑了

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mypassword';    

    我也用过

    UPDATE user SET authentication_string=password('mypassword') WHERE user='root';

但是我遇到了以下错误

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'mypassword'' at line 1

最佳答案

出现此错误是因为您使用的是 MySQL Connector/J 5.1.45 或更早版本。 MySQL 8 引入了新的身份验证机制 (caching_sha2_password),这些版本的驱动程序不支持该机制。

您需要升级到 MySQL Connector/J 5.1.46 或更高版本。截至撰写本文时,MySQL Connector/J 驱动程序的最新版本是 8.0.15。您可以从https://dev.mysql.com/downloads/connector/j/下载或者在Maven/Gradle等中指定正确的版本

关于java - 错误: Client does not support authentication protocol requested by server; consider upgrading MySQL client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56785395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com