mysql插入emoji表情报错(Incorrect string value:\x…)



Make sure all your tables’ default character sets and text fields are converted to utf8mb4, in addition to setting the client & server character sets, e.g. ALTER TABLE mytable charset=utf8mb4, MODIFY COLUMN textfield1 VARCHAR(255) CHARACTER SET utf8mb4,MODIFY COLUMN textfield2 VARCHAR(255) CHARACTER SET utf8mb4; and so on.If your data is already in the utf8 character set, it should convert to utf8mb4 in place without any problems. As always, back up your data before trying!

Also make sure your app layer sets its database connections’ character set to utf8mb4. Double-check this is actually happening – if you’re running an older version of your chosen framework’s mysql client library, it may not have been compiled with utf8mb4 support and it won’t set the charset properly. If not, you may have to update it or compile it yourself.

When viewing your data through the mysql client, make sure you’re on a machine that can display emoji, and run a SET NAMES utf8mb4 before running any queries.




电子邮件地址不会被公开。 必填项已用*标注