Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

mysql

jdbc

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

like image 942
sachin sarangamath Avatar asked May 19 '18 11:05

sachin sarangamath


People also ask

How do I enable authentication in MySQL?

Tutorial MySQL - Configure the authentication via PasswordInstall the MySQL service. Access the MySQL command-line. On the authentication prompt, a password is not required. Verify the authentication plugin and the password configured to the ROOT user account.

How do I update MySQL workbench?

Step 2: Navigate to Software > MySQL Upgrade or type “MySQL” into the search bar. You may also find it under SQL Services > MySQL/MariaDB Upgrade. Step 3: Select the version of MySQL you want to upgrade to and click Next. Now follow the upgrade steps, and it'll take care of everything for you.


2 Answers

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.

like image 65
Mark Rotteveel Avatar answered Sep 20 '22 02:09

Mark Rotteveel


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
like image 25
Shubham Mishra Avatar answered Sep 19 '22 02:09

Shubham Mishra