Last active
August 12, 2021 04:05
-
-
Save nhatnx/7e7b1efbbfa5e1a3c2e61779d3e9da3d to your computer and use it in GitHub Desktop.
[MySQL] Alter charset of all tables and their columns
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
-- Query to convert table and all its column type to utf8 | |
ALTER TABLE <Table_Name> CONVERT TO CHARACTER SET utf8; | |
-- Query to generate Alter Table for all tables | |
SELECT CONCAT("ALTER TABLE ", TABLE_SCHEMA, '.', TABLE_NAME," CONVERT TO CHARACTER SET utf8;") AS ExecuteTheString | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_SCHEMA="<Database_Name>" | |
AND TABLE_TYPE="BASE TABLE"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment