Last active
December 13, 2017 02:10
-
-
Save tuliren/74861e18c27f4ad6cf39ebd6e0baade5 to your computer and use it in GitHub Desktop.
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
# 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