Skip to content

Instantly share code, notes, and snippets.

@tuliren
Last active December 13, 2017 02:10
Show Gist options
  • Save tuliren/74861e18c27f4ad6cf39ebd6e0baade5 to your computer and use it in GitHub Desktop.
Save tuliren/74861e18c27f4ad6cf39ebd6e0baade5 to your computer and use it in GitHub Desktop.
# Show database charset
SELECT default_character_set_name FROM information_schema.SCHEMATA
WHERE schema_name = "<database>";
# Chase database charset
ALTER DATABASE <database> CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
# Show table charset
SELECT CCSA.character_set_name, T.table_name FROM information_schema.`TABLES` T,
information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "<database>";
# Change table charset
ALTER TABLE <table> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
# Show column charset
SELECT table_name, column_name, character_set_name FROM information_schema.`COLUMNS`
WHERE table_schema = "<database>";
# Change column charset
ALTER TABLE <table> CHANGE <column> <column> <type, e.g. VARCHAR(191)> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment