problem phenomenon
Insert data into Mysql database, an exception occurs
SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\x9F\x90\x94\xF0\x9F...' for column 'COLUMN_NAME' at row 1;
nested exception is java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\x94\xF0\x9F...' for column 'COLUMN_NAME' at row 1
problem analysis
Check the data saved to Column and find that the saved data contains Emoji expressions
Emoji expression is 4 bytes, while MYSQL 5.5.18 version UTF8 is three bytes
Solution
Convert Mysql database character encoding from utf8 to utf8mb4
Specific operation steps
1. Modify MySQL character encoding
Modify my.cnf
[mysqld]
character-set-server=utf8mb4
[mysql]
default-character-set=utf8mb4
Restart Mysql after modification
2. Modify the character encoding of the database table
Command: alter table TABLE_NAME convert to character set utf8mb4 collate utf8mb4_bin; (replace TABLE_NAME with your table name)