我正在使用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>
最后…… Changesets / 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”和“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"
或者在liquibase.properties文件中:
url: jdbc:mysql://localhost/dbname?useUnicode=true&characterEncoding=UTF-8