0

I'm using wordpress as CMS, Plesk is host and I got a question. I understand that for the database to store emojis, the charset should be changed to utf8mb4.

  1. Where do I change it?
  2. Is there any global setting so that every site uses the new utf8mb4?
  3. And how do I change it to an existing database which has emojis stored already?

Because it really hurts when migrating to new servers. All the emojis then appear as ? when importing database.

1 Answers1

1

Step 1, change your database's default charset:

ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

if the db is not created yet, create it with correct encodings:

CREATE DATABASE database_name DEFAULT CHARSET = utf8mb4 DEFAULT COLLATE = 
utf8mb4_unicode_ci;

Step 2, set charset when creating table:

CREATE TABLE IF NOT EXISTS table_name (
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;

or alter table

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE table_name MODIFY field_name TEXT CHARSET utf8mb4;

Source

Mohit Chandel
  • 1,838
  • 10
  • 31