Incorrect string value: '\xF0\x9F...' for column 'XXX' at row 1
The reason for this problem is that UTF-8 encoding may be two, three, or four bytes. Emoji expressions or some special characters are 4 bytes, and Mysql's utf8 encoding is up to 3 bytes, so the data cannot be inserted.
There are many solutions, such as:
1. Filter emoji expressions in the program;
2. Modify the database encoding to utb8mb4
Method 2 instructions:
Modify my.cnf
[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci
Then restart mysql command: /etc/init.d/mysqld start
Change the corresponding field in the database to utf8mb4_general_ci
Modify the url connecting to the database in the project and remove characterEncoding=utf-8. This step must be performed.
This is mysql5.6. Older notes