mysqldump 脚本上的无效 utf8 字符串

Invalid utf8 character string on mysqldump script

我创建了一个数据库副本并将排序规则和字符集更改为 utf8mb4(最初是 latin1),然后使用 mysqldump 创建了一个脚本Flyway 数据库迁移。

当我运行下面的脚本

-- MySQL dump 10.13  Distrib 5.5.62, for Win64 (AMD64)
--
-- Host: localhost    Database: feedback
-- ------------------------------------------------------
-- Server version   8.0.15

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Dumping data for table `COMPONENT_GROUP`
--

LOCK TABLES `COMPONENT_GROUP` WRITE;
/*!40000 ALTER TABLE `COMPONENT_GROUP` DISABLE KEYS */;
INSERT INTO `COMPONENT_GROUP` VALUES ('AAAB','AAA - MOTOR','LUBRIFICAÇÃO DO MOTOR','LUBRIFICAÇÃO DO MOTOR',NULL,NULL,20181219,1)
UNLOCK TABLES;


/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2019-05-22 13:07:38

flyway 显示如下消息:

WARNING: DB: Invalid utf8 character string: 'C7C34F' (SQL State: HY000 - Error Code: 1300)
WARNING: DB: Incorrect string value: '\xC3O FUN...' for column 'claimed_name_pt' at row 10 (SQL State: HY000 - Error Code: 1366)

当我 运行 使用 SQLyog 和 MySQL Workbench 等工具转储脚本时,数据已正确插入,那么我该如何为 Flyway 解决这个问题?

找到修复迁移问题的缺失部分。我必须将编码设置添加到 Flyway 的连接字符串中:

FLYWAY_URL="jdbc:mysql://${db_instance.default.address}:3306/${mysql_database.db-app.name}?characterEncoding=UTF-8&useUnicode=true"