Skip to content
Eduardo Lira

BANCO-DE-DADOS

How to Convert MySQL Database Character Set to UTF-8

Learn how to easily convert a MySQL database character set to UTF-8.

To convert a MySQL database character set to UTF-8 follow the steps below.

In the sql tab of your phpmyadmin administrator execute the following sql commands (In local environment or not, use a database administrator with option to execute queries. If you have advanced knowledge, feel free too).

To convert only database to UTF8.

ALTER DATABASE databasename character
SET utf8mb4 COLLATE utf8mb4_unicode_ci;

To convert each table to UTF8.

ALTER TABLE tablename1 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE tablename2 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

This conversion process can be useful for you to fix errors or adapt your database with a new server after content migration.

Thx!

Revisited in November 2026

I changed the commands in this 2015 post, for two reasons:

  • Syntax error. For the tables I had written characterSET, as one word. MySQL doesn’t accept it: it’s two words, CHARACTER SET.
  • MySQL’s utf8 isn’t full UTF-8. It stores at most 3 bytes per character and can’t hold emoji or some characters from other languages. Full UTF-8 in MySQL is called utf8mb4 and has existed since MySQL 5.5.3, from 2010. Since MySQL 8.0, from 2018, it’s the default, and the old utf8 (now called utf8mb3) is deprecated. That’s why the commands now use utf8mb4.

Before converting, three precautions:

  • Back up the database.
  • ALTER DATABASE only changes the default for tables created afterwards. Existing ones need ALTER TABLE, one by one.
  • On MySQL before 5.7.7, indexes on VARCHAR(255) columns can exceed the size limit with utf8mb4, and ALTER TABLE fails. If that happens, the error tells you which index.

Who writes this

Eduardo Lira

Software developer in Rio de Janeiro. I started this blog in 2012, in technical support at a hosting company, writing down the fixes for the problems that came up every day. Today I work at Sofis Tecnologia, on critical healthcare systems and SQL Server database migrations.

Found a mistake in this post?

A command that no longer works, a broken link, wrong information: tell me what you saw. The message goes only to the author and is not shown on the site.