0

When we want to store a string with emojis to our MySQL database, we get this error:

Conversion from collation utf8_general_ci into utf8mb4_unicode_520_ci impossible for parameter

Can someone explain to me why Node is sending it as utf8 to MySQL and how I can declare that we have an utf8mb4 collation? I tried several different encodings on the database side, but I think it is a Node.js or driver configuration that is missing.

The backend is based on Express.js, running on a Debian system within an lts-alpine docker container and the request is sent by a React Native app.

Thx, Florian

Florian
  • 81
  • 6
  • I don't think this has anything to do with Node.js. The problem is probably that your connections use a different character set than the database. You should configure your DB connections to use utf8mb4. – GOTO 0 Feb 09 '22 at 17:07
  • Does this answer your question? [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – JosefZ Feb 09 '22 at 17:09
  • 3
    Maybe https://stackoverflow.com/questions/71034035/encoding-issues-storing-emojis-in-mysql-how-can-i-define-a-character-collation/71054524?r=SearchResults&s=1|14.7148#71054524 – Rick James Feb 09 '22 at 19:42
  • Thanks! You are right, the client uses utf8 instead of utf8mb4 as I get `'character_set_connection': 'utf8mb3'` when I query `SHOW VARIABLES LIKE 'character_set_%'`. It seems to be a prisma.io issue as I am not able to pass the argument `?charset=UTF8MB4` to the prisma-mysql client. This is the docs about passing arguments, but it somehow does not work ... https://www.prisma.io/docs/concepts/database-connectors/mysql#connection-details – Florian Feb 16 '22 at 08:57

0 Answers0