我在docker容器中运行我的应用程序,其中flyway迁移工具在连接到MySQL DB(8.0.11)时出错:这是完整的错误:Unable to obtain connection from database (jdbc:mysql://docker-mysql:3306) for user deepti: Client d...

我在docker容器中运行我的应用程序,其中flyway迁移工具在连接到MySQL DB(8.0.11)时出错:
这是完整的错误:
Unable to obtain connection from database (jdbc:mysql://docker-mysql:3306) for user 'deepti': Client does not support authentication protocol requested by server. Consider upgrading MariaDB client. plugin was = caching_sha2_password
这是我的docker-compose.yml:
version: '3' services: docker-mysql: image: mysql:8.0.11 environment: - MYSQL_ROOT_PASSWORD=... - MYSQL_DATABASE=test1 - MYSQL_USER=... - MYSQL_PASSWORD=... flyway-service-i: image: boxfuse/flyway command: -url=jdbc:mysql://docker-mysql:3306 -schemas=test1 -user=... -password=... migrate volumes: - "../resources/db/migration:/flyway/sql" depends_on: - docker-mysql spring-boot-jpa-docker-webapp: image: deepti/spring-boot-docker depends_on: - docker-mysql ports: - 8080:8080 environment: - DATABASE_HOST=docker-mysql - DATABASE_USER=... - DATABASE_PASSWORD=... - DATABASE_NAME=test1 - DATABASE_PORT=3306
任何人都可以帮我这个.谢谢
解决方法:
MySQL中的默认身份验证方法在version 8.0.4中更改为caching_sha2_password.它看起来不像MariaDB connector supports it.
您可以通过添加如下所示的命令将default authentication plugin恢复为旧版本:
version: '3'
services:
docker-mysql:
image: mysql:8.0.11
command: --default-authentication-plugin=mysql_native_password
environment:
...
对于已使用caching_sha2_password身份验证方法创建的db中的任何现有用户,您可以更改用户以使用mysql_native_password:
ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';
或者只使用docker-compose rm删除现有容器.
我在this repository创建了一个工作示例.这是成功的输出:
Flyway Community Edition 5.1.4 by Boxfuse
Database: jdbc:mysql://docker-mysql:3306/test1 (MySQL 8.0)
WARNING: You are connected to a MySQL database using the MariaDB driver. This is known to cause issues. An upgrade to Oracle's MySQL JDBC driver is highly recommended.
Successfully validated 1 migration (execution time 00:00.010s)
Creating Schema History table: `test1`.`flyway_schema_history`
Current version of schema `test1`: << Empty Schema >>
Migrating schema `test1` to version 1.0 - init
Successfully applied 1 migration to schema `test1` (execution time 00:00.290s)
正如您所看到的,虽然它可以正常工作,但是对于使用MySQL的MariaDB驱动程序的问题存在警告.
另一种选择是下载官方MySQL JDBC driver,将其添加到./drivers目录并将其挂载到Flyway容器中:
flyway-service-i:
image: boxfuse/flyway
command: ...
volumes:
- "./sql:/flyway/sql"
- "./drivers:/flyway/drivers"
这也有效:
Flyway Community Edition 5.1.4 by Boxfuse
Database: jdbc:mysql://docker-mysql:3306/test1 (MySQL 8.0)
Successfully validated 1 migration (execution time 00:00.011s)
Creating Schema History table: `test1`.`flyway_schema_history`
Current version of schema `test1`: << Empty Schema >>
Migrating schema `test1` to version 1.0 - init
Successfully applied 1 migration to schema `test1` (execution time 00:00.229s)
但要摆脱以下警告:
WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
我确实需要在jdbc url中添加verifyServerCertificate = false和useSSL = true:
jdbc:mysql://docker-mysql:3306/test1?verifyServerCertificate=false&useSSL=true
本文标题为:java – Docker Flyway MySQL 8:客户端不支持服务器请求的身份验证协议.考虑升级MariaDB客户端


- Spring Cloud oauth2 认证服务搭建过程示例 2023-02-05
- Java数据结构之优先级队列(PriorityQueue)用法详解 2023-02-28
- SpringBoot自定义starter启动器的实现思路 2023-06-23
- Java中的线程生命周期核心概念 2022-12-16
- jdbc+jsp简单留言 jdbc+mysql+jsp留言板 java留言板 jdbc留言板 jsp留言板 java留言簿 java期末作业 留言板期末作业 2023-11-04
- Springboot整合企业微信机器人助手推送消息的实现 2022-11-25
- JavaWeb Maven详解相关配置 2023-02-10
- Quarkus中ConfigSourceInterceptor的加密配置实现 2022-10-24
- Java设置String字符串编码方法详解 2023-07-15
- 是否有用于比较数据库架构的Java API 2023-11-03