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

5

9

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

Presswork answered 19/5, 2018 at 11:42 Comment(5)
ya ya i upgraded by running C:\Program Files\MySQL\MySQL Server 8.0\bin> mysql_upgrade -u root -p Enter password: ********** Checking if update is needed. This installation of MySQL is already upgraded to 8.0.11, use --force if you still need to run mysql_upgradePresswork
Which version of MySQL Connector/J are you using? Also, why do you think the error "Client does not support authentication protocol requested by server; consider upgrading MySQL client" has anything to do with granting privileges to the user? What is your source for that idea?Joist
i have used 8.0.11 , installed using MySql InstallerPresswork
Is that the version of MySQL you use, or the version of MySQL Connector/J (the MySQL JDBC driver), because to me the error seems to indicate that you are using a relatively old MySQL Connector/J driver (that is 5.1.45 or earlier).Joist
Thank u , u pointed out correctly , i was using old version of MySql Connector when replaced with the new version , it worked properly , Thanks a lotPresswork
J
13

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.

Joist answered 20/5, 2018 at 8:34 Comment(2)
hello, how can I update it? I have the same problem with an old program. I have to upgrade connector of it? How I can do that?Slowly
@AlfonsoSilvestri Either you need to update the maven (or gradle) dependencies of your application, or - if you don't use those tools - you will need to download it yourself from the MySQL site and replace your existing MySQL Connector/J library.Joist
F
2

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
Funke answered 19/2, 2020 at 11:3 Comment(0)
R
1

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
});
Rijeka answered 12/7, 2019 at 23:26 Comment(0)
T
1

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.

Tasimeter answered 16/8, 2019 at 6:42 Comment(0)
A
0

This issue comes when you try connect to a different version of mysql connector which is a newer version and it requires some security check up and stuff, but all of these are not competible with your project you are running.

So this is what i did :

  1. Open Mysql Installer : enter image description here

  2. Click reconfigure

  3. Click next

  4. Read this instructions and select this : enter image description here

5) Enter your root password, Next and Execute. 6) Now try redeploy or whatever.

Thought it will be useful

Abilene answered 9/1 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.