提问者:小点点

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


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

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

  • Flyway版本:flyway-8.5.11
  • 操作系统:windows 10
  • 证书:见 flyway.conf

我包括5个文件/代码片段,顺序如下:

  • docker compose.yml
  • mysql.Dockerfile
  • 我的.cnf
  • 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数据库的my.cnf文件

[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)

共1个答案

匿名用户

在docker-compose.yml中,而不是这个:

command: --default-authentication-plugin=mysql_native_password

尝试以下语法:

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