10

I am trying to insert emoji's into a certain filed in my mysql table. I ran alter command and changed the collation to "utf8mb4_general_ci"

  ALTER TABLE XYZ MODIFY description VARCHAR(250) CHARACTER SET utf8mb4
  COLLATE utf8mb4_general_ci;

Table details after above query:

+-------------+--------------+---------------+--------------------+
| Column      | Type         | Character Set | Collation          |
+-------------+--------------+---------------+--------------------+
| description | varchar(250) | utf8mb4       | utf8mb4_general_ci |
+-------------+--------------+---------------+--------------------+

After this I ran the query to update description column with emoji's, every time I ran below query, the emoji is replaced by '?'.

  update XYZ set description='a test with : 😄😄' where id = 1;

But when i print the result from a select query for the same id, it displays' '?' in place of emoji. The result was:

  "a test with : ??"

Carried out necessary changes into model file. Please accept my Apologies for not making it clear, would appreciate any lead in this matter.

5
  • Have you tried adding ’OPTIONS’: {’charset’: ’utf8mb4’} in django database configuration along with username and password ? Jun 12, 2017 at 10:41
  • Yes, i did that too.
    – Shrey
    Jun 12, 2017 at 10:45
  • Did you try to change /etc/mysql/my.cnf options?
    – Satevg
    Jun 12, 2017 at 14:00
  • Not really, what should i change in there?
    – Shrey
    Jun 12, 2017 at 14:02
  • Tried changing my.cnf file also, but its of no use.
    – Shrey
    Jun 13, 2017 at 11:34

2 Answers 2

22
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        ...
        'OPTIONS': {
                    'charset': 'utf8mb4',
                    'use_unicode': True, },
    },
}

my.cnf:

[mysqld]
character-set-server=utf8mb4
default-collation=utf8mb4_unicode_ci

[client]
default-character-set=utf8mb4
0

this save me on MYSQL 8.0.1

my.cnf

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
1
  • Were you using Django? (I hope you have updated past 8.0.1 -- that is a pre-release; one should move on to at least the "GA" version.)
    – Rick James
    Nov 14, 2022 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.