gpt4 book ai didi

java - 已经在使用 utf8mb4 但得到 1366 : Incorrect string value: '\xF0\x9F\x98\x81\xF0\x9F...'

转载 作者:行者123 更新时间:2023-11-29 03:22:56 25 4
gpt4 key购买 nike

“不正确的字符串值”问题的所有答案都指向使用 utf8mb4。但是,我仍在使用它,但仍然出现该错误。

运行

SELECT CCSA.character_set_name, collation_name FROM information_schema.`TABLES` T,
information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "test"
AND T.table_name = "products";

产生

character_set_name  collation_name
utf8mb4 utf8mb4_unicode_ci

和运行

SELECT character_set_name, collation_name FROM information_schema.`COLUMNS` 
WHERE table_schema = "test"
AND table_name = "products"
AND column_name = "description";

产生相同的结果。然后,当我尝试更新列 description 时:更新 test.products SET description='Esperienza molto negativa... 😁😁😁😁SCONSIGLIATISSIMO' WHERE id ='50'

我收到上述错误

1366: Incorrect string value: '\xF0\x9F\x98\x81\xF0\x9F...' for column 'description' at row 1

我已经通过 jdbc 连接 jdbc:mysql://localhost:3306/test?useUnicode=yes;characterEncoding=utf8; 和直接通过 MySQLWorkbench 尝试了此更新。我不知道还能尝试寻找什么。我错过了什么?

编辑SHOW CREATE TABLE

的输出
CREATE TABLE `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`manufacturerId_fk` int(11) NOT NULL,
`type_fk` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'TEST',
`ownerId_fk` int(11) DEFAULT NULL,
`rating_fk` int(11) NOT NULL,
`description` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`authorName` varchar(75) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`authorUrl` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `manufacturer_authorUrl_UNIQUE` (`manufacturerId_fk`,`authorUrl`),
KEY `fk_products_manufacturers_idx` (`manufacturerId_fk`),
KEY `fk_products_users_idx` (`ownerId_fk`),
KEY `fk_products_validRatings_idx` (`rating_fk`),
KEY `fk_products_productTypes` (`type_fk`),
CONSTRAINT `fk_products_productTypes` FOREIGN KEY (`type_fk`) REFERENCES `productTypes` (`type`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_products_manufacturers` FOREIGN KEY (`manufacturerId_fk`) REFERENCES `manufacturers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_products_validRatings` FOREIGN KEY (`rating_fk`) REFERENCES `validRatings` (`value`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=418 DEFAULT CHARSET=utf8mb4

最佳答案

我在文本字段中遇到了类似的问题。(MySQL 1366错误不正确的字符串值)

我确认数据库、表、列字符集都是utf8mb4

通过将字段类型更改为longtext 问题已解决。

希望这可以帮助某人。

关于java - 已经在使用 utf8mb4 但得到 1366 : Incorrect string value: '\xF0\x9F\x98\x81\xF0\x9F...' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40976571/

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