I have thousands of columns across hundreds of tables in about a hundred databases inside a MySQL instance that need to be upgraded from utf8mb3 to utf8mb4. Is there a way to generate ALTER
statements for every table and column that needs to change?
I'm upgrading MySQL hosted on Amazon RDS from MySQL 5.7 to 8.0. The Pre-patch compatibility tool tells me:
The following objects use the utf8mb3 character set. It is recommended to convert them to use utf8mb4 instead, for improved Unicode support.
More Information:
https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html
It then lists about 6,000 databases and columns that need to be updated:
mydb - schema's default character set: utf8
mydb.mytable.mycolumn - column's default character set: utf8
I'd like to be able to generate all the ALTER
statements I'll need to run similar to how MySQL command querying all MyISAM database helped my convert all my tables from MyISAM to Innodb.
Best Answer
Here is a query what will generate all the necessary update statements.
ALTER TABLE ... CONVERT
statement both updates the table default and all the columns within the table.When run, it should generate output like:
Sources: