Search code examples
c#mysqlunicodeutf-8utf-32

How do I insert 4 byte unicode characters into mysql database?


I'm occasionally getting following exception when someone tries to insert smiley into my database:

Incorrect string value: '\xF0\x9F\x98\x8A' for column 'name' at row 1

The name is defined as

`name` VARCHAR(255) CHARACTER SET utf32 COLLATE utf32_general_ci NOT NULL,`

And I'm using CharSet=utf8; in my connection string

What else should I check/change for full unicode insert to start working?


Solution

  • you have to change your collation of database table to utf8mb4_bin

    And set CHARACTER SET in database configuration as utf8mb4