Mysql 使用 jdbc 的连接错误
Mysql connection error using jdbc
我有一个非常严重的问题,两天内我无法继续我的任务。我使用 docker 和 mysql 服务器。我有 docker-compose.yml 文件,其中:
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!'
正在成功创建 docker 个图像。使用 dbeaver 客户端,我当然使用 mysql 驱动程序和确切的凭据设置连接:
服务器主机:localhost
端口:3306
数据库:我的项目
用户名:我的项目
密码:'alex1234!'
此外,我在驱动程序属性中将 allowPublicKeyRetrieval 设置为 true 并建立连接。
现在在我的 application.properties 文件中的 intellij 中我有完全相同的东西:
#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
当我 运行 应用程序面临此错误时:
Authentication plugin 'caching_sha2_password' cannot be loaded
为什么会这样?我也尝试了一些解决方案 ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password By 'password';
但什么都没有。请帮忙
在 MySQL 8.0 中,caching_sha2_password 是默认的身份验证插件,而不是 mysql_native_password。有关此更改对服务器操作以及服务器与客户端和连接器的兼容性的影响的信息,请参阅 caching_sha2_password 作为首选身份验证插件 -https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
您在 docker 个图像中使用 mysql8,它有不同的身份验证实现。
查看 caching_sha2_password 以下 link 的变化
所以暂时尝试将 mysql 版本降级到 5.7 。
并在旁注中通过 links 对 mysql-8 使用正确的步骤。看看下面的 link for jdbc-connector。
https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatible-connectors
我有一个非常严重的问题,两天内我无法继续我的任务。我使用 docker 和 mysql 服务器。我有 docker-compose.yml 文件,其中:
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!'
正在成功创建 docker 个图像。使用 dbeaver 客户端,我当然使用 mysql 驱动程序和确切的凭据设置连接: 服务器主机:localhost 端口:3306 数据库:我的项目 用户名:我的项目 密码:'alex1234!' 此外,我在驱动程序属性中将 allowPublicKeyRetrieval 设置为 true 并建立连接。 现在在我的 application.properties 文件中的 intellij 中我有完全相同的东西:
#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
当我 运行 应用程序面临此错误时:
Authentication plugin 'caching_sha2_password' cannot be loaded
为什么会这样?我也尝试了一些解决方案 ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password By 'password';
但什么都没有。请帮忙
在 MySQL 8.0 中,caching_sha2_password 是默认的身份验证插件,而不是 mysql_native_password。有关此更改对服务器操作以及服务器与客户端和连接器的兼容性的影响的信息,请参阅 caching_sha2_password 作为首选身份验证插件 -https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
您在 docker 个图像中使用 mysql8,它有不同的身份验证实现。
查看 caching_sha2_password 以下 link 的变化
所以暂时尝试将 mysql 版本降级到 5.7 。 并在旁注中通过 links 对 mysql-8 使用正确的步骤。看看下面的 link for jdbc-connector。 https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatible-connectors