You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

liquibase-maven-plugin生成changelog报错,寻求解决方案

解决Liquibase Maven插件生成Changelog时的编码错误问题

报错信息

Invalid string encoding on createTable.remarks. To resolve, remove the invalid character on the database and try again in changeSet

解决步骤

  • 排查数据库字符集配置
    执行SQL命令查看数据库字符集参数:

    show variables like 'char%';
    

    重点确认character_set_database、character_set_server、character_set_client、character_set_connection是否统一使用支持全字符的编码(如utf8mb4),避免因编码不一致导致注释解析失败。

  • 定位并清理表注释中的非法字符
    错误核心是表注释(remarks)存在编码不兼容的字符,按以下操作处理:

    1. 批量查询数据库中包含非法字符的表注释:
      SELECT table_name, table_comment 
      FROM information_schema.tables 
      WHERE table_schema = '你的数据库名称' 
      AND table_comment REGEXP '[^[:print:]]';
      
    2. 对查出的表,修改注释移除非法字符:
      ALTER TABLE `目标表名` COMMENT = '清理后的合法注释内容';
      
  • 配置Liquibase连接编码(可选)
    如果数据库字符集正常,但Liquibase连接时编码不匹配,可在pom.xml的liquibase插件配置中给JDBC URL添加编码参数:

    <plugin>
      <groupId>org.liquibase</groupId>
      <artifactId>liquibase-maven-plugin</artifactId>
      <configuration>
        <url>jdbc:mysql://localhost:3306/你的数据库名?useUnicode=true&characterEncoding=utf8mb4</url>
        <!-- 其他配置(用户名、密码等) -->
      </configuration>
    </plugin>
    
  • 重新生成Changelog
    完成上述操作后,执行生成命令:

    mvn liquibase:generateChangeLog
    

内容的提问来源于stack exchange,提问作者flmelody

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 00:31:39