gpt4 book ai didi

encoding - liquibase 破坏 UTF-8 变更集

转载 作者:行者123 更新时间:2023-12-02 14:41:34 30 4
gpt4 key购买 nike

我正在使用 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>

Changesets/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

关于encoding - liquibase 破坏 UTF-8 变更集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24405200/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com