简体   繁体   中英

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

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

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';

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

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.

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.

Run:

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

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
});

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.

If you are installing Jasper server with MySQL-8. And you're getting above error OR 'Access denied for user root@localhost' while running js-install-ce.bat / js-install-ce.bat test .

  1. Run mysql query: SELECT user,authentication_string,plugin,host FROM mysql.user;

Check the plugin column for 'root' user, it has to be 'mysql_native_password'. If the plugin value is 'caching_sha2_password' then you need to run update query: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

OR

  1. Re-Install MySQL. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM