Last active
October 31, 2019 14:55
-
-
Save heylastway/58d863605d5682391f3b535dc81f8eef to your computer and use it in GitHub Desktop.
How to convert all Database Tables and Columns to a specific Collation.
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
# 1.Convert the Collation of a Database | |
ALTER DATABASE DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci; | |
# 2.Convert the Collation of all Tables | |
SELECT CONCAT("ALTER TABLE ", TABLE_SCHEMA, '.', TABLE_NAME,' COLLATE utf8_general_ci;') | |
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DBNAME' AND TABLE_TYPE = 'BASE TABLE'; | |
# 3.Convert the Collation of Table Columns | |
SELECT CONCAT('ALTER TABLE `', TABLE_NAME,'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') AS mySQL | |
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= "DBNAME" AND TABLE_TYPE="BASE TABLE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment