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

Strapi Save Emoji as ???? (Question marks) in MySql Database #10676

Closed
iKunalmathur opened this issue Aug 2, 2021 · 10 comments
Closed

Strapi Save Emoji as ???? (Question marks) in MySql Database #10676

iKunalmathur opened this issue Aug 2, 2021 · 10 comments

Comments

@iKunalmathur
Copy link

Bug report

Describe the bug

Strapi Save Emoji as ???? (Question marks) in MySql Database

Steps to reproduce the behavior

  1. Download 'https://github.com/strapi/strapi-starter-next-blog'
  2. Connect with database in my case which is MySql
  3. Create a new article add a description containing Emoji(🙄).
  4. See error: Strapi Save Emoji As ???? in database.

Screenshots

Bug Image
strapi issue

System

  • Strapi Version: 3.6.5
  • Operating System: Windows 10
  • Database: MySQL
  • Node Version: 14.17.0
  • NPM Version: 6.14.13
  • Yarn Version: none

Additional context

it works fine with the default database (SQLite)

@derrickmehaffy
Copy link
Member

Can you please confirm what char encoding your MySQL database is set to?

As MySQL defaults to latin1 / latin1_swedish_ci instead of utf8mb4.

@iKunalmathur
Copy link
Author

@derrickmehaffy Hi Thanks for the response but I've changed encoding to utf8mb4_unicode_ci in phpMyAdmin but still, it doesn't work.
image

@derrickmehaffy
Copy link
Member

Make sure the database and the table are set to utf8mb4 and keep in mind that by changing that doesn't change the currently stored data, only new data will have that encoding.

@iKunalmathur
Copy link
Author

still don't work

@Milesssssss
Copy link

Still don`t work!!

@iKunalmathur
Copy link
Author

hey @machengda89 which database you are using??

@pierredarrieutort
Copy link

pierredarrieutort commented Nov 4, 2021

Hey, try to follow #10468 (comment).

1 - change wanted columns to utf8mb4_unicode_ci :
image

2 - In /config/database.js go to connections.default.settings and add charset: 'utf8mb4'

It works for me

@themtaysw
Copy link

Hey, try to follow #10468 (comment).

1 - change wanted columns to utf8mb4_unicode_ci : image

2 - In /config/database.js go to connections.default.settings and add charset: 'utf8mb4'

It works for me

works in a certain way for me... it tends to save some emojis normally, tho some of them are still as ????. any possible solution?

@danieltorres1109
Copy link

I add two lines on config/database:

charset: 'utf8mb4',
collation: 'utf8mb4_unicode_ci'

My code looks as:
mysql: { connection: { connectionString: env('DATABASE_URL'), host: env('DATABASE_HOST', 'localhost'), port: env.int('DATABASE_PORT', 3306), database: env('DATABASE_NAME', 'strapi'), user: env('DATABASE_USERNAME', 'strapi'), charset: 'utf8mb4', collation: 'utf8mb4_unicode_ci', password: env('DATABASE_PASSWORD', 'strapi'), ssl: env.bool('DATABASE_SSL', false) && { key: env('DATABASE_SSL_KEY', undefined), cert: env('DATABASE_SSL_CERT', undefined), ca: env('DATABASE_SSL_CA', undefined), capath: env('DATABASE_SSL_CAPATH', undefined), cipher: env('DATABASE_SSL_CIPHER', undefined), rejectUnauthorized: env.bool( 'DATABASE_SSL_REJECT_UNAUTHORIZED', true ), }, }, pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) }, },

@red-made
Copy link

I've done the following:

1- added, as mentioned before, in config/database:

charset: 'utf8mb4',
collation: 'utf8mb4_unicode_ci'

2- Edited the column:

ALTER TABLE
    table_name
    CHANGE column_name column_name
    LONGTEXT
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_unicode_ci;

3- Edited the table:

ALTER TABLE
    table_name
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_unicode_ci;

It's working like a charm

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

No branches or pull requests

7 participants