Skip to content

Instantly share code, notes, and snippets.

@nhatnx
Last active August 12, 2021 04:05
Show Gist options
  • Save nhatnx/7e7b1efbbfa5e1a3c2e61779d3e9da3d to your computer and use it in GitHub Desktop.
Save nhatnx/7e7b1efbbfa5e1a3c2e61779d3e9da3d to your computer and use it in GitHub Desktop.
[MySQL] Alter charset of all tables and their columns
-- 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