How to insert emoji character in a TEXT field of MYSQL?

2

I have a text editor. In this text editor, save the information in a table, using a column of type 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 encoding? How can I fix this?

    
asked by anonymous 23.08.2018 / 14:50

1 answer

7

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

ALTER DATABASE
    exemplo
    CHARACTER SET = utf8mb4
    COLLATE = utf8mb4_unicode_ci;

Another example applying charset to a specific column:

ALTER TABLE tabela MODIFY coluna VARCHAR(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    
23.08.2018 / 14:54