我使用的是Liquibase 2.0.5(但已经测试了最新的3.2.0无效),当我尝试用包含UTF-8字符的SQL更改集更新MySQL 5.5数据库时,所有更改集似乎都转换为ASCII,而不是波兰字母,我得到"?"。
下面是我使用的命令:java -jar liquibase.jar --changeLogFile=changesets.xml --url="jdbc:mysql://localhost/dbname" --username=user --password=pass --driver=com.mysql.jdbc.Driver --classpath=mysql-connector-java-5.1.21-bin.jar update
changeset.xml就像:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<include file="Changesets/2014.26/changesets.xml"/>
</databaseChangeLog>
变更集/2014.26/changesets.xml:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<changeSet id="20140623_1700" author="tmarcinkowski">
<sqlFile path="Changesets/2014.26/20140623_1700_tmarcinkowski_ss_303.sql"/>
</changeSet>
</databaseChangeLog>
最后……变更集/2014.26/20140623 _1700_tmarcinkowski_ss_303.sql:
INSERT INTO `catalog` (`category_id`, `parent_category_id`, `name`, `priority`, `photo`, `icon_catalog`, `icon_breadcrumbs`, `lft`, `rgt`) VALUES
(0, NULL, 'root', 0, '', '', '', 1, 1262),
(1, 0, 'Art. spożywcze', 1, '', '', '', 2, 755),
(2, 1, 'Owoce i Warzywa', 4, '', '', '', 3, 60),
(3, 1, 'Nabiał', 2, '', '', '', 61, 146),
(4, 1, 'Mięso, Wędliny', 5, '', '', '', 147, 206),
(5, 1, 'Ryby i Owoce morza', 9, '', '', '', 207, 234),
(6, 1, 'Mrożonki i lody', 10, '', '', '', 235, 266),
(7, 1, 'Pieczywo', 1, '', '', '', 267, 324);
附加——logLevel=debug显示已经损坏的字符。
DEBUG 6/25/14 11:17 AM:liquibase: SQLFile file:Changesets/2014.26/20140623_1700_tmarcinkowski_ss_303.sql
DEBUG 6/25/14 11:17 AM:liquibase: SQLFile file contents is:
INSERT INTO `catalog` (`category_id`, `parent_category_id`, `name`, `priority`, `photo`, `icon_catalog`, `icon_breadcrumbs`, `lft`, `rgt`) VALUES
(0, NULL, 'root', 0, '', '', '', 1, 1262),
(1, 0, 'Art. spo?ywcze', 1, '', '', '', 2, 755),
(2, 1, 'Owoce i Warzywa', 4, '', '', '', 3, 60),
(3, 1, 'Nabia?', 2, '', '', '', 61, 146),
(4, 1, 'Mi?so, W?dliny', 5, '', '', '', 147, 206),
(5, 1, 'Ryby i Owoce morza', 9, '', '', '', 207, 234),
(6, 1, 'Mro?onki i lody', 10, '', '', '', 235, 266),
(7, 1, 'Pieczywo', 1, '', '', '', 267, 324);
将"useJvmCharsetConverters=true"one_answers"charSet=UTF-8"附加到连接字符串中也没有帮助,就像在更改集的开头添加"SET NAMES utf8;"一样。所有文件都是UTF-8格式。
有人知道怎么处理吗?
这是Connector/J问题:自v5.1.3以来,Connector/J自动检测配置了character_set_server=utf8mb4的服务器或将使用characterEncoding=xxx传递的Java编码utf-8视为utf8mb4。
只需将useUnicode和characterEncoding参数添加到MySQL连接URL。
命令行:
-url="jdbc:mysql://localhost/dbname?useUnicode=true&characterEncoding=UTF-8"
或在液体中。属性文件:
url: jdbc:mysql://localhost/dbname?useUnicode=true&characterEncoding=UTF-8