MySQL插入数据报错:1366 Incorrect string value: '\xF0\xA0\xB9\xB3\xF0\xA0...' for column xxxx

[10501]SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xF0\xA0\xB9\xB3\xF0\xA0...' for column xxxx at row 1

是因为MySQL不能识别4个字节的 utf8 编码的字符,抛出了异常。

解决办法将字符类型换成改为 utf8mb4

数据库:

ALTER DATABASE `db_name` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

表:

ALTER TABLE `table_name` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

 

连接编码也要改成 utf8mb4

 

posted @ 2023-03-31 11:03  kjcy8  阅读(449)  评论(0编辑  收藏  举报