Mysql server utF8 character encoding, error when saving emoji:

java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x92\x94’ for column ‘name’ at row 1

Reason: UTF8 is three bytes, UTF8MB4 is four bytes and emoji is four bytes.

Solution 1 —– Configure one by one

  1. Modifying the database encoding

  1. Modify table encoding

  1. Modifying database Connections

driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test? useUnicode=true&autoReconnect=true&rewriteBatchedStatements=TRUE username=root password=root\

Java.sqlexception: Incorrect String Value: ‘\xF0\x9F\x92\x94’

Solution 2 —– Global configuration (refer to the specific configuration meaning)

My.cnf (Windows: my.ini) my.cnf is usually stored in /etc/mysql.my.cnf. Once found, please add the following contents in the following three sections:

[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect=’SET NAMES utf8mb4′

Reference: blog.csdn.net/a445849497/…

If the character set in the database is not utF8MB4, the character set in the database is not UTF8MB4. If the character set in the database is utF8MB4, the character set is not UTF8MB4. Insert data into utF8MB4 and set it to UTF8MB4Copy the code