一、背景
1、java项目,name含有表情插入到mysql数据库中报错 Incorrect string value: '\xF0\x9F\x92\x8BTi..
2、解决办法
(1)将字符串中的不合法字符替换掉
content = content.replaceAll("[\\x{10000}-\\x{10FFFF}]", "");
(2)修改字段或者表的字符集为 utf8mb4
alter table `table_name` convert to character set utf8mb4 collate utf8mb4_unicode_ci;
参考:https://stackoverflow.com/questions/13653712/java-sql-sqlexception-incorrect-string-value-xf0-x9f-x91-xbd-xf0-x9f
https://blog.csdn.net/hanjiyu/article/details/52982697