Explain Codes LogoExplain Codes Logo

Error 1115 (42000): Unknown character set: 'utf8mb4'

sql
mysql
character-set
database-configuration
Nikita BarsukovbyNikita Barsukov·Dec 6, 2024
TLDR

You're seeing ERROR 1115 (42000): Unknown character set: 'utf8mb4' because your MySQL version is pre-5.5.3, and it doesn't understand utf8mb4. To fix it, you have two options:

  1. Upgrade your MySQL to 5.5.3 or later to enable utf8mb4 support, (the recommended solution).

    or

  2. In case upgrading isn't a viable option, switch to the utf8 character set, which has broader compatibility across all versions:

    CREATE DATABASE mydb DEFAULT CHARACTER SET utf8;

    Substitute mydb with your actual database's name.

Squeeze out 'utf8mb4' from SQL dump

When system upgrade is impossible due to legacy constraints, the quickest solution is to alter the SQL dump manually.

  1. Using a text editor open your .sql file. VBox will do!

  2. Search for all instances of utf8mb4 and replace them with utf8. Ctrl+H is a programmer's best friend 🚀.

  3. Alter the character_set_client setting, if present, to utf8.

Cross-version Compatibility for Export

Note that when exporting data using mysqldump, the --compatible=mysql40 option ensures backward compatibility. Highly recommended when dealing with older MySQL versions.

Protect your Data

Downgrading from utf8mb4 to utf8 might cause data loss affecting the latest emojis. Those characters will either disappear or transform incomprehensibly. Always create a backup before playing 'data surgeon'!

Version Compatibility using PHPMyAdmin

When using PHPMyAdmin, check your server version and ensure it meets the requirements for utf8mb4. The platform also allows exports with parameters configured for compatibility.

Safe-guard for Shared Databases

When working on a shared server, set character_set_server to utf8 to standardize character sets and prevent conflicts. This practice is a life-saver in environments where clients might support different character sets.