Skip to content

Instantly share code, notes, and snippets.

@samstoller
Last active November 15, 2023 14:31
Show Gist options
  • Save samstoller/1f7b3d54eb8c2bee47ab to your computer and use it in GitHub Desktop.
Save samstoller/1f7b3d54eb8c2bee47ab to your computer and use it in GitHub Desktop.
Various ways to migrate between utf8 and utf8mb4 MySQL character sets
ALTER TABLE t1
DEFAULT CHARACTER SET utf8mb4,
MODIFY col1 CHAR(10)
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
MODIFY col2 CHAR(10)
CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;
# Export
mysqldump table_name > schema.sql
# Upgrade or Downgrade
sed 's/utf8/utf8mb4/g' schema.sql > upgrade.sql
sed 's/utf8mb4/utf8/g' schema.sql > downgrade.sql
# Import
mysql table_name < upgrade.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment