Last active
November 15, 2023 14:31
-
-
Save samstoller/1f7b3d54eb8c2bee47ab to your computer and use it in GitHub Desktop.
Various ways to migrate between utf8 and utf8mb4 MySQL character sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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