4

Since MySQL 8.0 has depreciated utf8mb3 (and will subsequently completely remove utf8mb3 support in future), what is the proper approach to upgrade/convert complete database (in production) from utf8mb3 (utf-8) to utf8mb4 with no (or minimal) downtime?

The problem is not converting, I know there exist multiple scripts for this conversion. My major concern is downtime. Is it possible to achieve this with no downtime?

Paul Spiegel
  • 30,925
  • 5
  • 44
  • 53
Rajat Goel
  • 2,207
  • 17
  • 35

2 Answers2

4

Assuming no Slaves, 8.0, no Triggers, and a few other things, I would recommend

pt-online-schema-change

It will CREATE TABLE with the new schema (utf8mb4), then copy the rows from the existing table (utf8 aka utf8mb3), and use Triggers to keep things in sync. There is a brief lock on the table at the end to finish up and swap tables.

You would do that one table at a time.

Doc: https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html

Also search around for it; sometimes abbreviated pt-osc.

With a Slave

Investigate the "failover" options and speed with RDS. If you can control the failover, then this method may be fast and 'simple' and possible. I assume it is really Master-Slave, not Master-Master?

  1. With the Slave, leave it replicating from the Master. (Potential problem: RBR may squawk at utf8 replicating to utf8mb4. This needs investigating.)
  2. Do ALTER TABLE ... CONVERT TO ... for each table on the Slave.
  3. Failover.
  4. Depending on what tools RDS has, it may be better to rebuild the Slave(s) from the new Master instead of doing ALTERs on the new Slave (which is the old Master).

Suggest you spin up some tiny instances with the same Master-Slave topology and version and charsets. Then try the steps. It does not need may rows, but it does need FOREIGN KEYs, Triggers, etc, in case any of them cause trouble. (Note how pt-osc has some issues with FKs.)

Rick James
  • 135,179
  • 13
  • 127
  • 222
0

With phpmyadmin, Select the database, then you'll get a view of all table structures, Select all tables,then select Operations at the top menu, you'll find a Collation feature, at the end of the page, select the utf8mb4_unicode_ci,then mark the "Change all tables collations" & "Change all tables columns collations" checkboxes, then click go. The operation takes utmost 7 seconds, and you are done.enter image description here

Abdalla Maro
  • 98
  • 1
  • 6