Storage Emoji with MySQL

Source: Internet
Author: User
Tags mysql backup

If you want your website or App to support Emoji, there are some details you need to know when setting up MySQL for the first time.

Emoji

The special point of the Emoji character is that it takes 4 bytes to store it. This collate of the UTF8 character set, which is common in MySQL, utf8_general_ci supports only 3 bytes. So to be able to store Emoji, you need to use a utf8mb4 character set instead.

When creating a table, use a statement like this:

CREATE TABLE ' tbl ' (...) Engine=innodb DEFAULT charset=utf8mb4 COLLATE utf8mb4_general_ci;
MySQL version

utf8mb4support for character sets is a new feature of MySQL 5.5, so you need to make sure that you are using at least 5.5 of the MySQL version. Basically, new projects after 2014 should be 5.6 straight.

MySQL Backup and Import

utf8mb4after the character set is enabled, the default parameters are no longer available for backup and import.

When backing up with mysqldump, you need to include:

Mysqldump--DEFAULT-CHARATER-SET=UTF8MB4

When restoring a backup or connecting through a program, you need to send the following SQL command after each connection is opened:

SET CHARSET UTF8MB4


Storage Emoji with MySQL

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.