MySQL Storage emoji issues

Source: Internet
Author: User
Tags mysql code

Some time ago, the project needs to be stored in the database emoji, due to the wrong encoding format, directly lead to database error, and then modify the MySQL code, it solved

Emoji symbols are actually text, not pictures, they are only displayed as pictures

Supported in mysql5.5.3 or later versions

After you have determined that the database supports store emoticons, you can modify the default encoding for the database so that you don't have to consider the problem of saving emoji if you build the database later.

In the MySQL configuration file my.cnf or My.ini configuration file, modify the following:

 [ client   default  -  - set  =   utf8mb4  [ mysqld   character  - set  - server =   utf8mb4collation  - server Span style= "color: #808080;" >=  utf8mb4_general_ci 

Restart MySQL, and then use the following command to view the encoding, which should be all utf8mb4 (except Character_set_filesystem and Character_set_system):

Mysql>Show variables like '%char%';+--------------------------+--------------------------+|Variable_name|Value|+--------------------------+--------------------------+|Character_set_client|Utf8mb4||Character_set_connection|Utf8mb4||Character_set_database|Utf8mb4||Character_set_filesystem| binary                   ||Character_set_results|Utf8mb4||Character_set_server|Utf8mb4||Character_set_system|Utf8||Character_sets_dir| /Usr/Local/Mysql-5.7....|+--------------------------+--------------------------+8Rowsinch Set(0.00Sec

Use the command to view the collation settings, which should all be utf8mb4_general_ci :

Mysql>Show variables like '%coll%';+----------------------+--------------------+|Variable_name|Value|+----------------------+--------------------+|Collation_connection|Utf8mb4_general_ci||Collation_database|Utf8mb4_general_ci||Collation_server|Utf8mb4_general_ci|+----------------------+--------------------+3Rowsinch Set(0.01Sec

If character_set_database It is utf8 , you need to restart the server.

Now, MySQL will be able to store the emoji characters correctly.

But what if it's a database that's been built before?

You can use the MySQL command

ALTER table name DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;

To change the encoding of existing database tables

Reference Address: https://www.liaoxuefeng.com/article/00145803336427519ae82a6c5b5474682c0c4ba5b47fb33000

MySQL Storage emoji issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.