Dee*_*i-l 4 java mysql flyway docker docker-compose
我在Docker容器中运行我的应用程序,在该容器中,flyway迁移工具在连接到MySQL DB(8.0.11)时出现错误:这是完整的错误:
无法从数据库(jdbc:mysql:// docker-mysql:3306)获取用户'deepti'的连接: 客户端不支持服务器请求的身份验证协议。 考虑升级MariaDB客户端。插件为= caching_sha2_password
这是我的docker-compose.yml:
版本:“ 3”
服务:
码头工人的MySQL:
图片:mysql:8.0.11
环境:
-MYSQL_ROOT_PASSWORD = ...
-MYSQL_DATABASE = test1
-MYSQL_USER = ...
-MYSQL_PASSWORD = ...
flyway-service-i:
图片:boxfuse / flyway
命令:-url = jdbc:mysql:// docker-mysql:3306 -schemas = test1 -user = ... -password = ...
数量:
-“ ../resources/db/migration:/flyway/sql”
依赖于取决于:
-码头工人的MySQL
spring-boot-jpa-docker-webapp:
图片:deepti / spring-boot-docker
依赖于取决于:
-码头工人的MySQL
端口:
-8080:8080
环境:
-DATABASE_HOST = docker-mysql
-DATABASE_USER = ...
-DATABASE_PASSWORD = ...
-DATABASE_NAME = test1
-DATABASE_PORT = 3306
谁能帮我这个忙。谢谢
在MySQL默认的身份验证方法改为caching_sha2_password在8.0.4版本。看起来MariaDB连接器不支持它。
您可以通过添加以下内容将默认身份验证插件恢复为旧版本command:
version: '3'
services:
docker-mysql:
image: mysql:8.0.11
command: --default-authentication-plugin=mysql_native_password
environment:
...
Run Code Online (Sandbox Code Playgroud)
对于已经使用caching_sha2_password身份验证方法创建的数据库中的任何现有用户,您可以更改用户以使用mysql_native_password:
ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';
Run Code Online (Sandbox Code Playgroud)
或仅使用删除现有容器docker-compose rm。
我已经在该存储库中创建了一个工作示例。这是成功的输出:
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)
Run Code Online (Sandbox Code Playgroud)
如您所见,尽管它可以工作,但是在将MariaDB驱动程序与MySQL结合使用时会出现警告。
另一种选择是下载官方的MySQL JDBC驱动程序,将其添加到./drivers目录中并将其安装在Flyway容器中:
flyway-service-i:
image: boxfuse/flyway
command: ...
volumes:
- "./sql:/flyway/sql"
- "./drivers:/flyway/drivers"
Run Code Online (Sandbox Code Playgroud)
这也起作用:
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)
Run Code Online (Sandbox Code Playgroud)
但是要摆脱以下警告:
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.
Run Code Online (Sandbox Code Playgroud)
我确实需要添加verifyServerCertificate=false并添加useSSL=true到jdbc网址:
jdbc:mysql://docker-mysql:3306/test1?verifyServerCertificate=false&useSSL=true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1918 次 |
| 最近记录: |