Mysql connection error using jdbc

Refresh

March 2019

Views

891 time

1

i have a really serious issue and i cannot continue my task for two days know. I use docker and mysql server. I have the docker-compose.yml file which this:

version: '2'
services:
  mongoDb:
    image: mongo:latest
    container_name: myproject-mongodb
    ports:
      - "27017:27017"

  mssql:
    image: mysql/mysql-server:8.0
    container_name: myproject-mysql
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: 'pass'
      MYSQL_DATABASE: 'myproject'
      MYSQL_USER: 'myproject'
      MYSQL_PASSWORD: 'alex1234!'

The docker images are being created successfully. Using dbeaver client i set up the connection using mysql driver of course and the exact credentials: server host: localhost port: 3306 Database: myproject User name: myproject password: 'alex1234!' Also i set the in the driver properties the allowPublicKeyRetrieval to true and the connection is established. Now in my intellij in application.properties file i have the exact same things:

#MySql WebMvcConfiguration.java
spring.datasource.url=jdbc:mysql://localhost:3306/myproject?allowPublicKeyRetrieval=true
spring.datasource.username=myproject
spring.datasource.password=alex1234!
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true

and when i ran the application im facing this error:

Authentication plugin 'caching_sha2_password' cannot be loaded

Why is this happening? I've also try some solutions ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password By 'password'; but nothing. Please help

1 answers

2

In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_native_password. For information about the implications of this change for server operation and compatibility of the server with clients and connectors, see caching_sha2_password as the Preferred Authentication Plugin -https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password

You are using mysql8 in docker images and it has a different implementation for authentication.

see caching_sha2_password changes in the following links

So for the time being try downgrading mysql version to 5.7 . And on the side note go through the links to use proper steps with mysql-8. Take a look at following link for jdbc-connector. https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatible-connectors