flyway 也真是够了, 动不动乱码,烦死了!
我的 命令是这样的:
flyway -driver=com.mysql.jdbc.Driver -user=root -password=123456 -url=jdbc:mysql://192.168.11.200:3316/test2 -outOfOrder=true -locations=filesystem:E:/dev/lk_sql migrate
表的行的内容出现了问号, column 的注释也是全是问号。
Windows上执行,出现了乱码,真特么奇了怪了。 但是同事机器上执行 同样的sql 就不会有乱码。
难道是系统编码的问题? 查看了下 cfcp 是一样的,都是 gbk
flyway.conf 配置不对? flyway.encoding 默认是关闭了的,而且上面写了 默认是 UTF-8, 我不需要改吧, 手动改为 UTF-8,一样的,还是不行。 难道 flyway 的bug ?
为什么同事那边就可以了呢?
把他的 flyway-5.1.4 安装包拿过来(也就是 flyway-commandline-5.1.4-windows-x64.zip), 重新搞一遍,发现也ok了!
真是搞不懂。 我的 flyway-5.1.4 好像也是 flyway-commandline-5.1.4-windows-x64.zip 解压得来的, 为什么就是不行呢? 难道 build 版本不同? 记不得了。。
算了,先这样吧。 我本地不行。尝试 Jenkins 执行运行 shell 的 flyway 命令 不行。 后面实在郁闷了,于是直接shell 执行 flyway migrate,发现 linux 直接执行也不行啊。。 为什么?
重新下载一个 flyway-5.2.4, 也不行。 我擦, 一直都是乱码, 真是郁闷。
真是没办法, 执行 flyway ,发现可以设置编码,通过: -configFileEncoding=utf8 -encoding=UTF-8。 两个都试过了, 都不行啊! 难道需要 jdbc url 指定 编码? 通过 ?useUnicode=true&characterEncoding=utf8 发现根本就执行不了。。
flyway -configFileEncoding=utf8 -driver=com.mysql.jdbc.Driver -user=root -password=123456 -url=jdbc:mysql://192.168.11.12:3306/test2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true -outOfOrder=true -locations=filesystem:E:/dev/lk_sql migrate
UTF-8 编码改成 UTF8 , GBK, 都于事无补。 真的 郁闷。
后面把flyway-commandline-5.1.4-windows-x64.zip 上传到别的 linux 机器,执行flyway migrate。发现好了,没有乱码了! 这个,难道跟 linux 的环境有关?
对比了 linux 系统语言, 发现是一样的啊。。
真是没办法, 这个编码问题真是难缠啊!! 网上搜索一把, 搞来搞去, 仍然解决不了任何问题啊!
执行 flyway ,发现可以通过-X 调试。 对比了 两个linux 机器上相同 flyway migrate 的debug 信息,发现了细微区别!
没有乱码的:
Flyway Community Edition 5.1.4 by Boxfuse DEBUG: Java 1.8.0_141 (Oracle Corporation) DEBUG: Linux 3.10.0-957.el7.x86_64 amd64 DEBUG: Loading config file: /app/flyway-5.1.4/conf/flyway.conf DEBUG: Unable to load config file: /root/flyway.conf DEBUG: Unable to load config file: /app/flyway-5.1.4/flyway.conf DEBUG: Using configuration: DEBUG: flyway.outOfOrder -> true DEBUG: flyway.jarDirs -> /app/flyway-5.1.4/jars DEBUG: flyway.password -> ****** DEBUG: flyway.url -> jdbc:mysql://192.168.11.200:3316/test2 DEBUG: flyway.driver -> com.mysql.jdbc.Driver DEBUG: flyway.encoding -> UTF-8 DEBUG: flyway.user -> root DEBUG: flyway.locations -> filesystem:/app/flyway-5.1.4/sql DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/derbyclient-10.14.2.0.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/mariadb-java-client-2.2.4.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/mssql-jdbc-6.4.0.jre7.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/sqlite-jdbc-3.20.1.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/h2-1.4.197.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/hsqldb-2.4.0.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/derby-10.14.2.0.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/jtds-1.3.1.jar DEBUG: Adding location to classpath: /app/flyway-5.1.4/drivers/postgresql-42.2.2.jre6.jar Database: jdbc:mysql://192.168.11.200:3316/test2 (MySQL 5.7) DEBUG: Driver : MariaDB connector/J 2.2.4 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. DEBUG: DDL Transactions Supported: false DEBUG: Schema: test2 DEBUG: Spring Jdbc available: false DEBUG: Scanning for SQL callbacks ... DEBUG: Scanning for filesystem resources at '/app/flyway-5.1.4/sql' (Prefix: '', Suffixes: '.sql') DEBUG: Scanning for resources in path: /app/flyway-5.1.4/sql (/app/flyway-5.1.4/sql) DEBUG: Filtering out resource: /app/flyway-5.1.4/sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt) DEBUG: Found filesystem resource: /app/flyway-5.1.4/sql/V1_1_1_6__ppm_issue_struct.sql DEBUG: Validating migrations ... DEBUG: Scanning for filesystem resources at '/app/flyway-5.1.4/sql' (Prefix: 'V', Suffixes: '.sql') DEBUG: Scanning for resources in path: /app/flyway-5.1.4/sql (/app/flyway-5.1.4/sql) DEBUG: Filtering out resource: /app/flyway-5.1.4/sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt) DEBUG: Found filesystem resource: /app/flyway-5.1.4/sql/V1_1_1_6__ppm_issue_struct.sql DEBUG: Scanning for filesystem resources at '/app/flyway-5.1.4/sql' (Prefix: 'R', Suffixes: '.sql') DEBUG: Scanning for resources in path: /app/flyway-5.1.4/sql (/app/flyway-5.1.4/sql) DEBUG: Filtering out resource: /app/flyway-5.1.4/sql/V1_1_1_6__ppm_issue_struct.sql (filename: V1_1_1_6__ppm_issue_struct.sql) DEBUG: Filtering out resource: /app/flyway-5.1.4/sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt) Successfully validated 1 migration (execution time 00:00.022s) DEBUG: Schema `test2` already exists. Skipping schema creation. Current version of schema `test2`: 1.1.1.6 WARNING: outOfOrder mode is active. Migration of schema `test2` may not be reproducible. Schema `test2` is up to date. No migration necessary.