79139630

Date: 2024-10-30 04:12:06
Score: 0.5
Natty:
Report link

I was experiencing the same problem as the OP, where emojis were being entered into strings that I needed to store in MySQL. What worked for me was a combination of four things:

  1. Added "?useUnicode=true&characterEncoding=utf8" to the end of my jdbc: connect string
  2. I had been using Class.forName("com.mysql.cj.jdbc.Driver") to register the JDBC driver, and that doesn't seem to work with UTF8MD4. I changed this to:
    DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
  3. Altered my table so the default character set for the table is UTF8MD4:
    ALTER TABLE mytable DEFAULT CHARACTER SET utf8mb4
  4. Altered the fields of my table that could contain emoji strings to be utf8md4:
    SET myfield utf8mb4 COLLATE utf8mb4_unicode_ci;

I did not seem to have to alter the entire database to be UTF8MD4, just the table and the fields of the table that would store these emoji strings.

Reasons:
  • Blacklisted phrase (0.5): I need
  • Whitelisted phrase (-1): worked for me
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: Tom McCaffrey