如何使用flyway -连接dockerized mysql数据库



我是新的flyway,并希望使用它对mysql数据库在docker(通过docker-compose)。我收到一个与加密相关的错误。让我困惑的是,我可以通过MySql工作台使用完全相同的凭据连接到它。我的文件夹结构与他们的文档中所示的相同:https://flywaydb.org/documentation/usage/commandline/

我迷失在试图得到它需要配置的任何关键东西上,文档也没有帮助。

  • Flyway版本:Flyway -8.5.11
  • 操作系统:windows 10
  • 凭据:参见flyway.conf

我包含了5个文件/代码片段,按顺序:

  • docker-compose.yml
  • mysql。Dockerfile
  • <
  • my . cnf中所做/gh>
  • flyway.conf
  • 我正在执行的flyway命令(和错误)

任何建议都是有帮助的。

docker-compose。yml文件

version: '3.9'
services:
mysql:
build: 
context: ./docker-compose/
dockerfile: mysql.Dockerfile
container_name: "mysql"
restart: always
command: --default-authentication-plugin=mysql_native_password
environment:
# MYSQL_DB_HOST: "mysql"
# MYSQL_DATABASE: "test_db"
# MYSQL_USER: "test_user"
# MYSQL_PASSWORD: "test_password_#"
MYSQL_ROOT_PASSWORD: "test_root_pass_#"
MYSQL_PORT: "3306"
ports:
- "3306:3306"
expose:
- "3306"
volumes:
# This is the my.cnf file that configures the database
- "./docker-compose/mysql/store:/var/lib/mysql" 

mysql容器Dockerfile (mysql.Dockerfile)

FROM mysql:8.0.29
COPY mysql/cnf/my.cnf /etc/my.cnf
RUN chmod 0444 /etc/my.cnf
COPY mysql/charsets/Index.xml  /usr/share/mysql-8.0/charsets/Index.xml
COPY mysql/charsets/latin1.xml /usr/share/mysql-8.0/charsets/latin1.xml
RUN chmod 0444 /usr/share/mysql-8.0/charsets/Index.xml
RUN chmod 0444 /usr/share/mysql-8.0/charsets/latin1.xml

mysql初始化文件

[MYSQLD]
default-storage-engine=InnoDB
collation-server = utf8mb4_0900_ai_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
tls_version=TLSv1.2,TLSv1.3
#Settings for Containers to work
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
user=mysql
# activate roles on login by default, so roles can be used easily
activate_all_roles_on_login=1
innodb_flush_method=O_DIRECT
#log_warnings is log_error_verbosity as of 5.7 and defaults to 3, the most verbose; log_warnings is no longer needed
#log_warnings=2
###GTIDs enablement, settings section
gtid_mode=ON
enforce-gtid-consistency=ON
key_buffer_size=128M
slow_query_log=1
slow_query_log_file=/var/lib/mysql/localDB-slow.log
long_query_time=3
table_open_cache=18432
table_open_cache_instances=8
#log-queries-not-using-indexes
log-bin=localDB-bin
log_error=localDB.err
relay-log=localDB-relay-bin
server-id=1
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
#set min word length to 3 for full text searching of FAQs
ft_min_word_len=2
#password_validation component settings
loose_validate_password.length=15
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4
host=127.0.0.1

我修改的flyway.conf的一部分(其他内容保持不变)

# Redshift*         : jdbc:redshift://<host>:<port>/<database>
flyway.url=jdbc:mysql://localhost:3306/fwtest
# Fully qualified classname of the JDBC driver (autodetected by default based on flyway.url)
# flyway.driver=
# User to use to connect to the database. Flyway will prompt you to enter it if not specified, and if the JDBC
# connection is not using a password-less method of authentication.
flyway.user=root
# Password to use to connect to the database. Flyway will prompt you to enter it if not specified, and if the JDBC
# connection is not using a password-less method of authentication.
flyway.password="test_user_pass_#"

我正在执行的命令,错误:

flyway migrate -configFiles="conf/flyway.conf"
ERROR: Unable to obtain connection from database (jdbc:mysql://localhost:3306/fwtest) for user 'root': Could not connect to address=(host=localhost)(port=3306)(type=master) : RSA public key is not available client side (option serverRsaPublicKeyFile 
not set)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State  : S1009
Error Code : 0
Message    : Could not connect to address=(host=localhost)(port=3306)(type=master) : RSA public key is not available client side (option serverRsaPublicKeyFile not set)
Caused by: java.sql.SQLTransientConnectionException: Could not connect to address=(host=localhost)(port=3306)(type=master) : RSA public key is not available client side (option serverRsaPublicKeyFile not set)
Caused by: java.sql.SQLException: RSA public key is not available client side (option serverRsaPublicKeyFile not set)

在docker-compose。Yml,而不是这个:

command: --default-authentication-plugin=mysql_native_password

试试这个语法:

command: ["--default-authentication-plugin=mysql_native_password"]

最新更新