Java 错误:客户端不支持服务器请求的认证协议;考虑升级 MySQL 客户端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50424900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:37:27  来源:igfitidea点击:

Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client

javamysqljdbc

提问by sachin sarangamath

While executing a JDBC program, I get the following error while connecting to database:

在执行 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)

When I researched this, I got to know that the below error is because I need to grant the privileges to the user, so follow

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

  1. mysql -u root -p
  2. then entered the password
  3. then I ran

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

    and also I used

    UPDATE user SET authentication_string=password('mypassword') WHERE user='root';
    
  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';
    

But I'm getting below error

但我得到以下错误

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

ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“IDENTIFIED BY 'mypassword'”附近使用的正确语法

采纳答案by Mark Rotteveel

This error occurs because you are using MySQL Connector/J 5.1.45 or earlier. MySQL 8 introduced a new authentication mechanism (caching_sha2_password) that is not supported in those versions of the driver.

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

You will need to upgrade to MySQL Connector/J 5.1.46 or higher. The latest version of the MySQL Connector/J driver at time of writing is 8.0.15. You can download it from https://dev.mysql.com/downloads/connector/j/or specify the right version in Maven/Gradle, etc.

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

回答by Aaron Adler

Run:

跑:

export MYSQL_PW='your_password'in your environment and use 'process.env.MYSQL_PW' as your password in the code below.

export MYSQL_PW='your_password'在您的环境中,并在下面的代码中使用“process.env.MYSQL_PW”作为您的密码。

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',  //your root username 
  database : 'your_database',   //the name of your db (create this if you haven't already)
  password : process.env.MYSQL_PW   //your root user's password
});

回答by avinash patil

Are you using MySQL 8.0.17 or greater than 5.7 version? uninstall this version because this version using SSH password-encryption that's why our database password they could not take. Install version 5.6 or 5.5 then it is working fine or you understand very well what the issue or what I am saying.

您使用的是 MySQL 8.0.17 还是 5.7 以上的版本?卸载此版本,因为此版本使用 SSH 密码加密,这就是他们无法使用我们的数据库密码的原因。安装 5.6 或 5.5 版,然后它就可以正常工作,或者您非常了解问题所在或我在说什么。

回答by Shubham Mishra

If you are installing Jasper server with MySQL-8. And you're getting this error while running js-install-ce.bat.

如果您使用 MySQL-8 安装 Jasper 服务器。并且您在运行js-install-ce.bat时收到此错误。

You just have to re-install MySQL-8 with Authentication Method as: "Use Legacy Authentication Method(Retain MySQL 5.x Compatibility)", as given in snapshot: enter image description here

您只需要使用身份验证方法重新安装 MySQL-8:“使用传统身份验证方法(保留 MySQL 5.x 兼容性)”,如快照中所示: 在此处输入图像描述