Amit
Amit

Reputation: 6294

MySQL handle unicode text for utf8mb4_unicode_ci

I am getting the following error when trying to insert a string to a table.

Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value: '\xF0\x9F\x98\x8D...' for column 'preview_text' at row 1

\xF0\x9F\x98\x8D is the smiling face emoji 😍

As I understand from previous stackoverflow questions, I need to set the collation to utf8mb4_unicode_ci, but it was like that by default, and still.

enter image description here

What else should I change?

Upvotes: 2

Views: 1733

Answers (1)

HTMHell
HTMHell

Reputation: 6006

Right after connection you should define the charset like so:

SET NAMES 'utf8mb4';

Usually you will have an option in your client to set it (more elegant than a query), for example: NodeJS:

mysql.createPool({
    ...
    charset : 'utf8mb4'
});

And PHP's MySQLi

$mysqli->set_charset("utf8mb4");

Upvotes: 1

Related Questions