Incorrect string value: ‘\xF0\x9F\x9A\x9A\xE5\x9C...‘ for column ‘newscontent‘ at row 1

The error message refers to the garbled characters stored after the text is parsed, but MySQL does not accept it. After querying, it is because the database is encoded as utf-8, which can only save three characters. It is possible that the data in the three-party interface has expressions or Chinese characters that can only be stored in four bytes. .

Solution:

1. Set the encoding of the database and tables to: utf8mb4, which is a superset of utf8 encoding, is backward compatible with utf8, and can store 4-byte emoji characters.

ALTER SCHEMA `db1`  DEFAULT CHARACTER SET utf8mb4 ;
ALTER TABLE `table1` 
CHARACTER SET = utf8mb4 ;

2. The character set of the table field also needs to be set to utf8mb4

ALTER TABLE `table1` 
CHANGE COLUMN `newscontent` `newscontent` TEXT CHARACTER SET 'utf8mb4' NULL DEFAULT NULL ;

Guess you like

Origin blog.csdn.net/luobowangjing/article/details/131827544