mysql insert table information error (transfer)

Today I made a function to get WeChat fans, and found that inserting the nickname into the database reported an error. The length must be enough

?
1
Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F

I found some information and found that the 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.

online solutions are

Modify mysql configuration

1. Find my.ini in the mysql installation directory and make the following modifications:
[mysqld]
character-set-server=utf8mb4
[mysql]
default-character-set=utf8mb4

2 reboot

net stop mysql
net start mysql

3 Modify the table

ALTER TABLE 表名 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

I only did step 3 and it solved my problem, now logging it

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326472981&siteId=291194637