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

How to connect to dockerized mysql database with flyway -

我是 flyway 的新手,想针对 docker 中的 mysql 数据库使用它(通过 docker-compose)。我收到与加密相关的错误。令我困惑的是,我可以通过 MySql workbench 使用完全相同的凭据很好地连接到它。我的文件夹结构与此处文档中的图片相同:https://flywaydb.org/documentation/usage/commandline/

我迷失了尝试获取它需要配置的任何关键内容,文档对它也没有帮助。

我包含 5 个 files/code 片段,顺序为:

任何建议都有帮助。

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 容器 (mysql.Dockerfile)

的 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

my.cnf 用于初始化 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"]