Created
February 17, 2020 10:21
-
-
Save tetz-akaneya/772e552d923e4b4f890490da04ea2bb8 to your computer and use it in GitHub Desktop.
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
use information_schema; | |
SELECT concat("ALTER DATABASE `",table_schema,"` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;") as _sql | |
FROM `TABLES` where table_schema like "yourDbName" group by table_schema; | |
SELECT concat("ALTER TABLE `",table_schema,"`.`",table_name,"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as _sql | |
FROM `TABLES` where table_schema like "yourDbName" group by table_schema, table_name; | |
SELECT concat("ALTER TABLE `",table_schema,"`.`",table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type,"(",character_maximum_length,") CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci",IF(is_nullable="YES"," NULL"," NOT NULL"),";") as _sql | |
FROM `COLUMNS` where table_schema like "yourDbName" and data_type in ('varchar','char'); | |
SELECT concat("ALTER TABLE `",table_schema,"`.`",table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type," CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci",IF(is_nullable="YES"," NULL"," NOT NULL"),";") as _sql | |
FROM `COLUMNS` where table_schema like "yourDbName" and data_type in ('text','tinytext','mediumtext','longtext'); | |
mysql -uroot < preAlterTables.sql | egrep '^ALTER' > alterTables.sql | |
mysql -uroot < alterTables.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dba.stackexchange.com/questions/8239/how-to-easily-convert-utf8-tables-to-utf8mb4-in-mysql-5-5