Monday, June 13, 2011

MySQL - Change Character Set and Collation

The following statement will update all tables to utf8. Change the char set and collate values to the desired character set and set the table schema to the schema you are modifying.


Backup DB before applying changes!!


SELECT CONCAT('ALTER TABLE `', t.`TABLE_SCHEMA`, '`.`', t.`TABLE_NAME`, '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') as stmt
FROM `information_schema`.`TABLES` t
WHERE 1
AND t.`TABLE_SCHEMA` = 'database_name'
ORDER BY 1

No comments:

Post a Comment