How to insert emoji character into a MYSQL TEXT field?

Asked

Viewed 518 times

3

I have a text editor. In this text editor, you save the information in a table, using a column like MEDIUMTEXT.

When I tried to insert an emoji, the following error appeared:

Incorrect string value: ' xF0 x9F x98 x83 xF0 x9F...' for column 'text' at Row 1

The collation of my table is utf8_unicode_ci.

Is there a problem with the encryption? How can I fix this?

1 answer

8


Use the "utf8mb4" charset. It will support storing the representation of the emoji string and other things that a common charset does not support. You can use an alter similar to this one if you need to change the whole bank charset:

ALTER DATABASE
    exemplo
    CHARACTER SET = utf8mb4
    COLLATE = utf8mb4_unicode_ci;

Another example applying the charset in a specific column:

ALTER TABLE tabela MODIFY coluna VARCHAR(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.