Reputation: 455
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
mysql -u root -p
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
Upvotes: 10
Views: 29444
Reputation: 455
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 :
5) Enter your root password, Next and Execute. 6) Now try redeploy or whatever.
Thought it will be useful
Upvotes: 0
Reputation: 21
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 .
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
Upvotes: 2
Reputation: 11
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.
Upvotes: 1
Reputation: 11
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
});
Upvotes: 1
Reputation: 109162
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.
Upvotes: 14