Warning
Error Code:
3778
MySQL Error 3778: Deprecated UTF8MB3 Collation Used
Description
This warning occurs when a database object (like a database, table, or column) attempts to use a collation belonging to the deprecated `UTF8MB3` character set. MySQL strongly recommends migrating to `UTF8MB4` to ensure full Unicode support, better compatibility, and to avoid future issues.
Error Message
'%s' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
Known Causes
4 known causesCreating New UTF8MB3 Objects
A `CREATE DATABASE`, `CREATE TABLE`, or `CREATE COLUMN` statement explicitly specifies a `UTF8MB3` collation, or the server's default is `UTF8MB3` for new objects.
Altering to Deprecated Collation
An `ALTER TABLE` or `ALTER DATABASE` statement attempts to change an existing object's character set or collation to a `UTF8MB3` variant.
Restoring Older Backups
Restoring a database backup from an older MySQL version or an environment where `UTF8MB3` was the default character set and collation.
Legacy Application Defaults
An application or ORM framework is configured with older settings that default to `UTF8MB3` when creating new database schema elements.
Solutions
3 solutions available1. Identify and Update Table and Column Collations medium
Locate and change all occurrences of the deprecated `utf8mb3` collation to `utf8mb4`.
1
Find all tables and columns using the deprecated `utf8mb3` collation. Replace `your_database_name` with your actual database name.
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLLATION_NAME LIKE 'utf8mb3%';
2
For each identified column, alter the table to change the collation to `utf8mb4_unicode_ci` (or another appropriate `utf8mb4` collation). This example assumes you want to change the collation of `your_column` in `your_table` within `your_database_name`.
ALTER TABLE your_database_name.your_table MODIFY COLUMN your_column VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3
Repeat the `ALTER TABLE` command for all columns identified in the first step. You may need to adjust the data type and length (`VARCHAR(255)` in the example) to match your original column definition.
/* Repeat for each affected column */
2. Update Database and Table Default Character Set and Collation medium
Set the default character set and collation for the entire database and existing tables to `utf8mb4`.
1
Check the current default character set and collation for your database.
SHOW VARIABLES LIKE 'character_set_database';
2
If the default is `utf8mb3`, alter the database to set the default character set to `utf8mb4` and a suitable collation like `utf8mb4_unicode_ci`.
ALTER DATABASE your_database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
3
After changing the database default, you may still need to update existing tables. You can do this by iterating through your tables and altering them. This command alters all tables in `your_database_name`.
SELECT CONCAT('ALTER TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'your_database_name' AND CHARACTER_SET_NAME = 'utf8mb3';
4
Execute the generated `ALTER TABLE` statements from the previous step. Be cautious, as this can be a resource-intensive operation for large databases.
/* Execute the output from the previous command */
3. Configure MySQL Server Defaults advanced
Globally set MySQL server defaults to `utf8mb4` to prevent future `utf8mb3` usage.
1
Locate your MySQL configuration file. Common locations include `/etc/my.cnf`, `/etc/mysql/my.cnf`, or `/etc/mysql/mysql.conf.d/mysqld.cnf`.
ls /etc/my.cnf /etc/mysql/my.cnf /etc/mysql/mysql.conf.d/mysqld.cnf
2
Edit the configuration file and add or modify the `[mysqld]` section to include the following settings. If `character-set-server` or `collation-server` already exist, update them.
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
3
You may also want to set the default client character set. Add or modify this in the `[client]` section.
[client]
character-set-client=utf8mb4
4
Save the configuration file and restart the MySQL server for the changes to take effect.
sudo systemctl restart mysql
5
Verify the server settings after restarting.
SHOW VARIABLES LIKE 'character_set_server';
SHOW VARIABLES LIKE 'collation_server';