Search code examples
phpmysqlutf-8utf8mb4

Can I safely use utf8 tables and columns in utf8mb4 mysql database?


I want at least some columns in my database to use utf8mb4 because they have to store text that includes emoji. I've been testing some stuff locally for a fairly large project and I've followed the steps in this guide (https://mathiasbynens.be/notes/mysql-utf8mb4) and did the following:

  • I modified the database so the character set is utf8mb4 and collate is utf8mb4_unicode_ci.
  • I however did not modify all the tables and columns to utf8mb4, but only 2 tables and 1 column in each table.
  • I also modified the connection to be utf8mb4.
  • Ran repair and optimize for both those tables.

Working with emoji for these columns is now possible.

I've read that utf8mb4 is fully compatible with utf8, and from what I've tested everything seems fine. The question is: Is this safe to do?


Solution

  • I've read that utf8mb4 is fully compatible with utf8, and from what I've tested everything seems fine. The question is: Is [mixing utf8 and utf8mb4 in the same database] safe to do?

    Yes.