Skip to content

Instantly share code, notes, and snippets.

@erkattak
Created August 28, 2012 15:08
Show Gist options
  • Save erkattak/3498909 to your computer and use it in GitHub Desktop.
Save erkattak/3498909 to your computer and use it in GitHub Desktop.
Get all queries to convert base tables in a given database to specific character set and collation
SELECT
DISTINCT CONCAT(
'ALTER TABLE `',
`COLUMNS`.`TABLE_SCHEMA`,
'`.`',
`COLUMNS`.`TABLE_NAME`,
'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;'
)
FROM
`information_schema`.`COLUMNS`
JOIN
`information_schema`.`TABLES` ON
`TABLES`.`TABLE_SCHEMA` = `COLUMNS`.`TABLE_SCHEMA`
AND
`TABLES`.`TABLE_NAME` = `COLUMNS`.`TABLE_NAME`
WHERE
`COLUMNS`.`TABLE_SCHEMA` = '471712_yah10'
AND
(
`COLUMNS`.`COLLATION_NAME` IS NOT NULL
AND
`COLUMNS`.`COLLATION_NAME` NOT LIKE 'utf8_uni%'
)
AND
`TABLES`.`TABLE_TYPE` = 'BASE TABLE';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment