Migrating MySQL 8.0 Default Charset from latin1 to utf8mb4: A Step‑by‑Step Guide
This article explains why MySQL 8.0 switched its default character set to utf8mb4 and provides two detailed migration plans—including configuration changes, data export/import, table and column conversion, and post‑migration testing—to help users safely upgrade their databases.
When MySQL 8.0 changed its default character set from latin1 to utf8mb4 , many systems that previously used utf8 (limited to three‑byte characters) need to migrate to support four‑byte characters such as rare glyphs and emojis.
Migration Plan 1 (Create a New Instance)
Prepare a new MySQL instance and modify my.cnf (or my.ini ) with the following settings: [mysqld] ## Character Settings init_connect='SET NAMES utf8mb4' character-set-server = utf8mb4 collation-server = utf8mb4_general_ci skip-character-set-client-handshake ## InnoDB Settings innodb_file_format = Barracuda innodb_file_format_max = Barracuda innodb_file_per_table = 1 innodb_large_prefix = ON
Stop the application, monitor SHOW MASTER STATUS to ensure no new writes are occurring.
Export the schema: mysqldump -u -p --no-data --default-character-set=utf8mb4 --single-transaction --set-gtid-purged=OFF --databases testdb > /backup/testdb.sql
Export the data: mysqldump -u -p --no-create-info --master-data=2 --flush-logs --routines --events --triggers --default-character-set=utf8mb4 --single-transaction --set-gtid-purged=OFF --database testdb > /backup/testdata.sql
Modify the dumped DDL, replacing every occurrence of utf8 with utf8mb4 .
Import the schema: mysql -u -p testdb < /backup/testdb.sql
Import the data: mysql -u -p testdb < /backup/testdata.sql
Create the required database users in the new instance.
Change the new MySQL port, restart the service, and point the application to the new instance for testing.
Migration Plan 2 (In‑Place Conversion)
Stop the application to avoid table locks during conversion.
Shut down MySQL and back up the data directory (or perform a full logical backup).
Update the same configuration parameters shown in Plan 1 and restart MySQL.
Convert each table: ALTER TABLE t CONVERT TO CHARACTER SET utf8mb4; Note: This copies the whole table, may be slow, and locks writes.
Convert specific columns if needed (e.g., CHAR columns): ALTER TABLE t MODIFY a CHAR CHARACTER SET utf8mb4; Impact is similar to table conversion.
Convert the database itself (metadata only, fast): ALTER DATABASE sbtest CHARACTER SET utf8mb4;
Update the JDBC URL to include characterEncoding=utf8mb4 (or utf-8 as appropriate).
After migration, verify that the application reads and writes Unicode characters correctly and that no data loss occurred.
Community Announcements
The article also includes a brief notice about upcoming community activities, such as free Mycat diagnostics, a call for technical article submissions on MySQL, DBLE, and DTLE, and contact information for the open‑source community.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.