How to save emoji special characters in MySQL database

Source: Internet
Author: User

MySQL added this UTF8MB4 code after version 5.5.3, Mb4 is the most bytes 4 meaning, specifically for compatibility with four-byte Unicode. In fact, UTF8MB4 is a superset of UTF8, theoretically using UTF8, and then modifying the character set to UTF8MB4, will not have any problems with the existing UTF8 encoded reads.

Small program of the project, found to save the user information nickname times wrong, looking for reasons to find that some users nickname is with emoji emoji, and the database table property settings at that time character encoding or UTF8, the database will of course error. After searching for some information on the Internet, we found the complete solution:

1. Modify the Database,table,column character set:

  1. ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
  2. ALTER TABLE table_name CONVERT to CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  3. ALTER TABLE table_name Change column_name VARCHAR (191) CHARACTER SET utf8mb4 COLLATE utf8mb4_  Unicode_ci;

2. Edit the My.cnf file and add the following to the corresponding section:

    1. [Client]
    2. default-character-set = Utf8mb4
    3. [MySQL]
    4. default-character-set = Utf8mb4
    5. [Mysqld]
    6. character-set-client-handshake = FALSE
    7. character-set-server = utf8mb4
    8. Collation-server = Utf8mb4_unicode_ci
    9. init_connect=' SET NAMES utf8mb4 '

Restart the MySQL service to

How to save emoji special characters in the MySQL database

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.