9

I'm getting error

Cannot establish a connection to jdbc:mysql://localhost:3306/world?zeroDateTimeBehavior=convertToNull using com.mysql.jdbc.Driver (Unable to load authentication plugin 'caching_sha2_password'.)

in netbean established the connection.

enter image description here

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Vijay Kumar
  • 4,059
  • 3
  • 11
  • 6
  • your driver/db too old? ...https://support.chartio.com/knowledgebase/unable-to-load-authentication-plugin-when-trying-to-connect-to-mariadb https://www.spigotmc.org/threads/mysql-errors-unable-to-load-authentication-plugin-caching_sha2_password.304616/ ... https://github.com/dbeaver/dbeaver/issues/1042 – xerx593 May 05 '18 at 20:40
  • 1
    Now I'm getting "Cannot establish a connection to jdbc:mysql://localhost:3306/new?zeroDateTimeBehavior=convertToNull using com.mysql.jdbc.Driver (java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long)" error – Vijay Kumar May 06 '18 at 11:34
  • ..still (driver<>db) version problems: https://coderanch.com/t/674877/databases/error-connect-mysql-database (when we are still in scope of "netbeans": You have to adjust them (in addition to other system/project driver-libs): Services(Tab)>Databases>Drivers) – xerx593 May 06 '18 at 11:44

2 Answers2

24

The newer versions of MySQL default to caching_sha2_password. If you want to disable it then follow below steps

  1. Login in to your MYSQL console as root user like below.

eg mysql -u YOUR_ROOT_USER_NAME -p YOUR_ROOT_USER_PASSWORD

  1. Then execute the command by replacing YOUR_ROOT_USER_NAME and YOUR_ROOT_USER_PASSWORD

ALTER USER 'YOUR_ROOT_USER_NAME'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_ROOT_USER_PASSWORD';

You will no longer get any 'caching_sha2_password' exception while connecting for any client after this.

Kishor Pawar
  • 3,386
  • 3
  • 28
  • 61
utpal416
  • 899
  • 5
  • 15
  • After following your answer, now there is an another exception: java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long – sansingh Jun 10 '18 at 09:48
  • This changes is nothing to do with Java. This answer is mainly related to the MySQL database. Typically to solve Java ClassCastException check your code,driver and java version. @sansingh ..Check this thread for the accepted answer for your problem https://stackoverflow.com/questions/46131295/exception-during-connection-to-mysql-in-java – utpal416 Jun 10 '18 at 16:40
  • 2
    This worked for me on my MySQL 8.0.19 – Ashutosh K Singh Mar 20 '20 at 19:38
  • 1
    Note, that the said user is not necessary defined for host `localhost`. You can query which host's the user belongs with `SELECT host, user FROM mysql.user;` and change `ALTER USER 'YOUR_ROOT_USER_NAME'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_ROOT_USER_PASSWORD';` accordingly. – Jenya Y. Jun 07 '20 at 06:30
  • This worked for me! ALTER USER 'YOUR_ROOT_USER_NAME'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_ROOT_USER_PASSWORD'; DB version= mysql 8.0.21 – Mata Jul 23 '20 at 07:39
  • If it doesn't work at first, run `FLUSH PRIVILEGES;` and try again – Gunar Gessner Sep 27 '20 at 18:08
-4

follow these steps:

  • just turn off the firewall on the system and security on control panel,
  • create a new dynamic web project
  • copy all the class fields and java files from the project
  • add jar in build path version 8.0
  • select tomcat in project facets
  • copy jAR in lib
  • try running jdbcconnection program

it will run.