Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a database which now needs to support 4 byte characters (Chinese). Luckily I already have MySQL 5.5 in production.

So I would just like to make all collations which are utf8_bin to utf8mb4_bin.

I believe there is no performance loss/gain with this change other than a bit of storage overhead.

share|improve this question
Use ALTER TABLE tbl_name [[DEFAULT] CHARACTER SET charset_name] [COLLATE collation_name] –  Raihan Nov 22 '11 at 18:31
I think he wants to make everything utf8mb4_bin, meaning tables and columns. –  Glen Solsberry Nov 22 '11 at 20:37

2 Answers 2

From How to support full Unicode in MySQL databases, here are the queries you can run to update the charset and collation of a database, a table, or a column:

# For each database:
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
# For each table:
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
# For each column:
ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
# (Don’t blindly copy-paste this! The exact statement depends on the column type, maximum length, and other properties. The above line is just an example for a `VARCHAR` column.)

Note, however, that you cannot fully automate the conversion from utf8 to utf8mb4. As described in step 4 of the abovementioned guide, you’ll need to check the maximum length of columns and index keys, as the number you specify has a different meaning when utf8mb4 is used instead of utf8.

Section 10.1.11 of the MySQL 5.5 Reference Manual has some more information on this.

share|improve this answer
According to the ALTER TABLE syntax (dev.mysql.com/doc/refman/5.5/en/alter-table.html) CONVERT TO handles conversion between the character sets for each column, modifying the column type where appropriate. I think that means ALTER-ing each column is redundant. Is there some reason each column must be ALTER-ed? –  CatShoes Aug 27 '13 at 19:23
@CatShoes: your point is supported by this discussion: dchua.com/2014/08/15/migrating-from-utf8-to-utf8mb4-in-mysql –  davide Mar 10 at 5:43

I would write a script (in Perl, or whatever) to use information_schema (TABLES and COLUMNS) to walk through all the tables, and do MODIFY COLUMN on every CHAR/VARCHAR/TEXT field. I would collect all the MODIFYs into a single ALTER for each table; this will be more efficient.

I think (but am not sure) that Raihan's suggestion only changes the default for the table.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.