Last active
April 8, 2016 10:15
-
-
Save andyj/5543d91d6b1c61012a4ab1832af1a978 to your computer and use it in GitHub Desktop.
Change all CHARACTER SETs in a Mysql database.sql
This file contains 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
-- This pull back a list of tables which have NON-UTF8 encoded columns and creates a SQL script to fix them (and the table itself) | |
SELECT CONCAT("ALTER TABLE ",t.TABLE_SCHEMA,".",t.TABLE_NAME," CHARACTER SET utf8 COLLATE utf8_general_ci;", | |
"ALTER TABLE ",t.TABLE_SCHEMA,".",t.TABLE_NAME," CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;") | |
AS sql_to_copy_and_run | |
FROM information_schema.TABLES t | |
INNER JOIN information_schema.`COLUMNS` c ON t.TABLE_SCHEMA = c.TABLE_SCHEMA | |
WHERE | |
t.TABLE_SCHEMA = ? -- Replace ? with your Database/Schema name | |
AND t.table_type = 'BASE TABLE' AND character_set_name IS NOT NULL AND character_set_name <> 'utf8' | |
GROUP BY t.TABLE_SCHEMA, t.TABLE_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment