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=  -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. by Boxfuse

DEBUG: Java 1.8.0_141 (Oracle Corporation)
DEBUG: Linux 3.10.-.el7.x86_64 amd64 DEBUG: Loading config file: /app/flyway-5.1./conf/flyway.conf
DEBUG: Unable to load config file: /root/flyway.conf
DEBUG: Unable to load config file: /app/flyway-5.1./flyway.conf
DEBUG: Using configuration:
DEBUG: flyway.outOfOrder -> true
DEBUG: flyway.jarDirs -> /app/flyway-5.1./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-
DEBUG: flyway.user -> root
DEBUG: flyway.locations -> filesystem:/app/flyway-5.1./sql
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/derbyclient-10.14.2.0.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/mariadb-java-client-2.2..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/mssql-jdbc-6.4..jre7.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/sqlite-jdbc-3.20..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/h2-1.4..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/hsqldb-2.4..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/derby-10.14.2.0.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/jtds-1.3..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/postgresql-42.2..jre6.jar
Database: jdbc:mysql://192.168.11.200:3316/test2 (MySQL 5.7)
DEBUG: Driver : MariaDB connector/J 2.2.
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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
DEBUG: Found filesystem resource: /app/flyway-5.1./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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
DEBUG: Found filesystem resource: /app/flyway-5.1./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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./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./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
Successfully validated migration (execution time :.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.

有乱码的:

Flyway Community Edition 5.1. by Boxfuse

DEBUG: Java 1.8.0_144 (Oracle Corporation)
DEBUG: Linux 3.10.-957.1..el7.x86_64 amd64 DEBUG: Loading config file: /app/flyway-5.1./conf/flyway.conf
DEBUG: Unable to load config file: /root/flyway.conf
DEBUG: Unable to load config file: /app/flyway-5.1./flyway.conf
DEBUG: Using configuration:
DEBUG: flyway.outOfOrder -> true
DEBUG: flyway.jarDirs -> /app/flyway-5.1./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-
DEBUG: flyway.user -> root
DEBUG: flyway.locations -> filesystem:/app/flyway-5.1./sql
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/derbyclient-10.14.2.0.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/mariadb-java-client-2.2..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/mssql-jdbc-6.4..jre7.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/sqlite-jdbc-3.20..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/h2-1.4..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/hsqldb-2.4..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/derby-10.14.2.0.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/jtds-1.3..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/postgresql-42.2..jre6.jar
Thu Jul :: CST 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.
Database: jdbc:mysql://192.168.11.200:3316/test2 (MySQL 5.7)
DEBUG: Driver : MySQL Connector Java mysql-connector-java-5.1. ( Revision: fe1903b1ecb4a96a917f7ed3190d80c049b1de29 )
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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
DEBUG: Found filesystem resource: /app/flyway-5.1./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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
DEBUG: Found filesystem resource: /app/flyway-5.1./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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./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./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
Successfully validated migration (execution time :.044s)
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.
[root@localhost flyway-5.1.]#
[root@localhost flyway-5.1.]# ./flyway -encoding=UTF- -driver=com.mysql.jdbc.Driver -user=root -password= -url=jdbc:mysql://192.168.11.200:3316/test2 -outOfOrder=true -X migrate
Flyway Community Edition 5.1. by Boxfuse DEBUG: Java 1.8.0_144 (Oracle Corporation)
DEBUG: Linux 3.10.-957.1..el7.x86_64 amd64 DEBUG: Loading config file: /app/flyway-5.1./conf/flyway.conf
DEBUG: Unable to load config file: /root/flyway.conf
DEBUG: Unable to load config file: /app/flyway-5.1./flyway.conf
DEBUG: Using configuration:
DEBUG: flyway.outOfOrder -> true
DEBUG: flyway.jarDirs -> /app/flyway-5.1./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-
DEBUG: flyway.user -> root
DEBUG: flyway.locations -> filesystem:/app/flyway-5.1./sql
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/derbyclient-10.14.2.0.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/mariadb-java-client-2.2..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/mssql-jdbc-6.4..jre7.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/sqlite-jdbc-3.20..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/h2-1.4..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/hsqldb-2.4..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/derby-10.14.2.0.jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/jtds-1.3..jar
DEBUG: Adding location to classpath: /app/flyway-5.1./drivers/postgresql-42.2..jre6.jar
Thu Jul :: CST 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.
Database: jdbc:mysql://192.168.11.200:3316/test2 (MySQL 5.7)
DEBUG: Driver : MySQL Connector Java mysql-connector-java-5.1. ( Revision: fe1903b1ecb4a96a917f7ed3190d80c049b1de29 )
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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
DEBUG: Found filesystem resource: /app/flyway-5.1./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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
DEBUG: Found filesystem resource: /app/flyway-5.1./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./sql (/app/flyway-5.1./sql)
DEBUG: Filtering out resource: /app/flyway-5.1./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./sql/put-your-sql-migrations-here.txt (filename: put-your-sql-migrations-here.txt)
Successfully validated migration (execution time :.045s)
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.

可以看到 driver 有所区别:

好的是:

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: Driver  : MySQL Connector Java mysql-connector-java-5.1.47 ( Revision: fe1903b1ecb4a96a917f7ed3190d80c049b1de29 )

把 上面命令的 驱动改一下:-driver=org.mariadb.jdbc.Driver  就好了!!

想起来了, 原来我处理过上面的WARNING, 而正是这个处理,导致了 这一系列的问题啊!

flyway 的drivers 目录, 默认是没有 mysql-connector-java-5.1.47.jar 的, 我看到执行 migrate的时候出现了 mariadb 的警告, 所以换成了 mysql, 同时把 设定了 -driver=com.mysql.jdbc.Driver

默认, 当然是不需要设置这个的!( 后面才知道,这完全是画蛇添足, 引起 非常大的 困惑。浪费大量时间 )

默认flyway-commandline-5.1.4-windows-x64.zip 解压得到的 flyway-5.1.4  的 drivers 目录是没有  mysql-connector-java-5.1.47.jar 的,

那为什么 flyway-5.2.4 是我下载的, 为什么也不行呢?它是通过 执行下载的:

wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/5.2.4/flyway-commandline-5.2.4-linux-x64.tar.gz | tar xvz && sudo ln -s `pwd`/flyway-5.2.4/flyway /usr/local/bin

它默认就有mysql 驱动啊!  真是坑爹。 我开始还以为是 jenkins 编码配置问题呢!

总结:

把 mysql 的驱动 去掉,或改一下 driver 为 mariadb 都可以解决问题。

一些细小的改动,可能引起很大问题。最好是 保持 原样。 warn 都不要动它的, 一动就出问题。

有时候, 推倒重来会更快。

flyway 非常坑爹的中文乱码问题的更多相关文章

  1. mysql保存中文乱码的原因和解决办法

    当你遇到这个mysql保存中文乱码问题的时候,期待找到mysql保存中文乱码的原因和解决办法这样一篇能解决问题的文章是多么激动人心.    也许30%的程序员会选择自己百度,结果发现网友已经贴了很多类 ...

  2. JBPM4.4GPD设计器中文乱码问题的另一种解决方法

    在eclipse中使用JBPM4.4的设计器时,输入中文后直接查看Source发现xml里中文全都乱码了,这时候大约整个人都不好了!赶紧百度.谷歌,搜到的多数结果都是要你在eclipse.ini或my ...

  3. 关于Idea里设置Terminal为Git/bin/bash.exe中文乱码的问题的终极解决方案

    1.这里如果设置为Git/git-bash.exe确实不会乱码,但是每次点Idea里的Terminal都会弹出一个单独的terminal窗口而非在idea子窗口里出现: 2.因此需要设置为Git/bi ...

  4. 老项目用webpack中文乱码问题解决记录

    有个很久(有多久呢,你还记得jquery1.6的年代吗...)的项目需要新加一些功能,又想使用新的生产力工具比如说webpack,es6,vue神马的.原来的项目整体都是用GBK编码的,这特么...坑 ...

  5. Cuba studio框架中使用thymeteaf模板时中文乱码

    最近公司换了Cuba这个orm框架,框架中使用了thymeteaf模板技术,发现在html中解析汉字一直是乱码的存在 一直以为是tomcat的问题但是tomcat的server.xml,项目中的web ...

  6. springmvc配置一:ajax请求防止返回中文乱码配置说明

    Spring3.0 MVC @ResponseBody 的作用是把返回值直接写到HTTP response body里. Spring使用AnnotationMethodHandlerAdapter的 ...

  7. python使用zipfile解压文件中文乱码问题

    中文在编程中真实后娘养的,各种坑爹,python3下中文乱码这个问题抓破了头皮,头疼.看了alex的文章,才有种恍然大悟的感觉(链接在底部). 一句话,就是转换成unicode,压缩前是什么编码,使用 ...

  8. java中文乱码解决之道(一)-----认识字符集

    沉寂了许久(大概有三个多月了吧),LZ"按捺不住"开始写博了! java编码中的中文问题是一个老生常谈的问题了,每次遇到中文乱码LZ要么是按照以前的经验修改,要么则是baidu.c ...

  9. MAC下 mysql不能插入中文和中文乱码的问题总结

    MAC下 mysql不能插入中文和中文乱码的问题总结 前言 本文中所提到的问题解决方案,都是基于mac环境下的,但其他环境,比如windows应该也适用. 问题描述 本文解决下边两个问题: 往mysq ...

随机推荐

  1. CCNA 之 十三 广域网概述

    广域网概述 为什么需要WAN ? 分区或分支机构的员工需要与总部通信并共享数据: 组织经常需要与其他组织远距离共享信息: 经常出差的员工需要访问公司网络信息: 什么事广域网链路? 用于连接LAN的.跨 ...

  2. DS1302时钟芯片驱动程序

    /***************************************************************************** FileName : DS1302.c F ...

  3. docker镜像、docker容器导入导出命令

    一.docker镜像导入导出命令 导出命令: docker save -o <保存路径> <镜像名称:标签> docker save -o ./test.tar test:la ...

  4. Reactive(3)5分钟理解 SpringBoot 响应式的核心-Reactor

    目录 一.前言 二. Mono 与 Flux 构造器 三. 流计算 1. 缓冲 2. 过滤/提取 3. 转换 4. 合并 5. 合流 6. 累积 四.异常处理 五.线程调度 小结 参考阅读 一.前言 ...

  5. java抽象类,接口(接口定义,实现接口,instanceof运算符,对象转换)

    抽象类 在面向对象的概念中,所有的对象都是通过类来表述的,但并不是所有的类都能够完整的描绘对象,如果一个类中没有包含足够的信息来描绘一类具体的对象,这样的类就是抽象类.抽象类往往用来表征对问题领域进行 ...

  6. IO到NIO的一个转变

    本内容来源:Jack视频讲解和自己的一个理解. 1.故事还得从网络模型或者IO开始聊起 2.你有想过传统IO真正存在的问题吗? 3.如果你是设计者,IO可以怎样改进? 4.NIO原理分析以及代码实现 ...

  7. JavaScript2 基础

    运算符 赋值运算符  用于给变量赋值. y=5;/z=2; 算术运算符  即算数符号,是基本算数运算.+ 加 / - 减/ * 乘/ / 除/ % 取余数/ ++ 自增(y++先赋值再自增/++y先自 ...

  8. Spring Cloud第八篇 | Hystrix集群监控Turbine

    ​ 本文是Spring Cloud专栏的第八篇文章,了解前七篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Clo ...

  9. 支付宝支付功能(使用支付宝sdk)

    1.准备参数        新建一个公共参数配置类NewAlipayconfig (可将参数存放到config配置文件中读取)          public class NewAlipayconfi ...

  10. 菜鸟系列docker——docker网络(8)

    Docker网络 Docker在容器内部运行应用,这些应用之间的交互依赖于大量不同的网络,这意味着Docker需要强大的网络功能. Docker 网络从覆盖范围可分为单个 host 上的容器网络和跨多 ...