UnderHost
Knowledgebase Docs

UTF-8 encoding: store international characters

Set UTF-8 encoding for databases, tables, and columns to support international characters (accents, emoji, CJK).

On this page

UTF-8 is the universal character encoding supporting all languages, accents, emoji, and special characters. Modern applications should always use UTF-8.

Why UTF-8 matters

Without UTF-8:

  • Accented characters (é, ñ, ü) display as ??? or garbled text
  • Asian characters (Chinese, Japanese, Korean) won't display
  • Emoji show as corrupted characters
  • International domain names (IDN) display incorrectly

Check current encoding

SHOW CREATE DATABASE mydatabase\G  # Check database collation
SHOW CREATE TABLE mytable\G  # Check table collation
SHOW FULL COLUMNS FROM mytable;  # Check column collation

Set UTF-8 when creating

Create database with UTF-8

CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Create table with UTF-8

CREATE TABLE users (
  id INT PRIMARY KEY,
  name VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Convert existing tables to UTF-8

ALTER DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE mytable CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Use utf8mb4, not utf8

MySQL's "utf8" is limited to 3 bytes and doesn't support emoji. Always use utf8mb4 for full UTF-8 support.

Related: Database administration

Was this article helpful?

Need hosting for database-backed apps?

Run WordPress, CMS, PHP apps, and MySQL/MariaDB workloads on UnderHost hosting, VPS, or managed servers.

Related articles

Back to Database