Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: Multibyte characters do not survive db/backup unless db charset is explicitly set to utf8mb4 in config #16753

Open
mmikkel opened this issue Feb 21, 2025 · 1 comment
Assignees
Labels

Comments

@mmikkel
Copy link
Contributor

mmikkel commented Feb 21, 2025

What happened?

Description

When backing up the database using the db/backup CLI command or Craft's "Database Backup" utility, multibyte characters (such as emojis) used in native fields (title fields, alternative text) or PlainText custom fields, will be exported as a '?' (question mark) unless CRAFT_DB_CHARSET is explicitly set to utf8mb4.

Note: I have not set/configured the backupCommand config setting.

Steps to reproduce

  1. Make sure the database is using utf8mb4 charset and utf8mb4_0900_ai_ci collation (i.e. Craft 5's defaults).
  2. Also make sure that the charset isn't explicitly set via the CRAFT_DB_CHARSET env var or in a config/db.php file
  3. Create an entry, and add a fire emoji (🔥) in its title.
  4. Backup the database using the db/backup CLI command, or the "Database Backup" utility
  5. Re-import the database dump from the db/backup command
  6. Confirm that the 🔥 in the entry's title has been replaced by a question mark ?

Repeat the process, but this time make sure there is a CRAFT_DB_CHARSET=utf8mb4 environment variable, before backing up the database. This time, the fire emoji will be intact.

Expected behavior

Multibyte characters in native and plaintext fields should be preserved when Craft dumps a database using the utf8mb4 charset and utf8mb4_0900_ai_ci collation.

Actual behavior

Multibyte characters in native and plaintext fields are exported as ? unless CRAFT_DB_CHARSET is set to utf8mb4.

Craft CMS version

5.6.9.1

PHP version

8.2.27

Operating system and version

DDEV v1.24.2

Database type and version

MySQL 8.0.40

Image driver and version

No response

Installed plugins and versions

None

@i-just
Copy link
Contributor

i-just commented Feb 24, 2025

Hi, thanks for reporting! I raised a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants