Created
August 19, 2013 09:33
-
-
Save seebz/6267332 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
| -- | |
| -- from `utf8_general_ci` to `utf8_unicode_ci` | |
| -- | |
| -- Génère la requêtes de convertion de la DB `{DB_NAME}` | |
| SELECT CONCAT('ALTER DATABASE `', schema_name, '` DEFAULT COLLATE utf8_unicode_ci;') | |
| FROM information_schema.schemata | |
| WHERE default_collation_name = 'utf8_general_ci' | |
| AND schema_name = '{DB_NAME}' | |
| -- union | |
| UNION | |
| -- Génère les requêtes de convertions des tables de la base `{DB_NAME}` | |
| SELECT CONCAT('ALTER TABLE `', table_schema, '`.`', table_name, '` COLLATE utf8_unicode_ci;') AS query | |
| FROM information_schema.tables | |
| WHERE table_collation = 'utf8_general_ci' | |
| AND table_type <> 'SYSTEM VIEW' | |
| AND table_schema <> 'mysql' | |
| AND table_schema = '{DB_NAME}' | |
| -- union | |
| UNION | |
| -- Génère les requêtes de convertions des champs de la base `{DB_NAME}` | |
| SELECT CONCAT('ALTER TABLE `', table_schema, '`.`', table_name, '` CHANGE `', column_name, '` `', column_name, '` ', column_type, ' CHARACTER SET utf8 COLLATE utf8_unicode_ci', | |
| IF(is_nullable = 'NO', ' NOT NULL', ''), ';') AS query | |
| FROM information_schema.columns | |
| WHERE table_schema NOT IN ('information_schema', 'mysql', 'tmp') | |
| AND collation_name IS NOT NULL | |
| AND character_set_name IS NOT NULL | |
| AND collation_name = 'utf8_general_ci' | |
| AND table_schema = '{DB_NAME}' | |
| -- union | |
| UNION | |
| -- Génère les requêtes de convertions des contenus des tables de la base `{DB_NAME}` | |
| SELECT CONCAT('ALTER TABLE `', table_schema, '`.`', table_name, '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;') AS query | |
| FROM information_schema.tables | |
| WHERE table_collation = 'utf8_general_ci' | |
| AND table_type <> 'SYSTEM VIEW' | |
| AND table_schema <> 'mysql' | |
| AND table_schema = '{DB_NAME}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment