Enable MySQL to support Emoji expressions

Source: Internet
Author: User
Tags check character
Let MySQL support Emoji expressions. We recommend that you use the utf8mb4 character set in advance for MySQL databases involving wireless connections. What is the difference between utf8mb4 and utf8? Previous

Let MySQL support Emoji expressions. We recommend that you use the utf8mb4 character set in advance for MySQL databases involving wireless connections. What is the difference between utf8mb4 and utf8? Previous

Let MySQL support Emoji expressions. We recommend that you use the utf8mb4 character set in advance for MySQL databases involving wireless connections.

What is the difference between utf8mb4 and utf8? In the past, mysql utf8 had a maximum of 3 characters, while utf8mb4 was extended to a single character with a maximum of 4 bytes. Therefore, more character sets are supported.

Solution: Convert Mysql encoding from utf8 to utf8mb4.

Required> = MySQL 5.5.3 and slave database must also be 5.5. Earlier versions do not support this character set or duplicate error.

Stop the MySQL Server Service

Modify my. cnf or mysql. ini

[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
Init_connect = 'set NAMES utf8mb4'

Restart MySQL Server and check Character Set

Mysql> show variables where Variable_name LIKE 'character \ _ set \ _ % 'OR Variable_name LIKE 'colation % ';

Modify the database character set:

Alter database database_name character set = utf8mb4 COLLATE = utf8mb4_unicode_ci;

Modify the character set of a table:

Alter table table_name convert to character set utf8mb4 COLLATE utf8mb4_unicode_ci;

Modify the character set of a field:

Alter table table_name CHANGE column_name VARCHAR (191) character set utf8mb4 COLLATE utf8mb4_unicode_ci;

If you only need to modify the character set of a field

In addition, do not add the characterEncoding parameter to the connection parameters of the server connection Database Connector/J. If this parameter is not added, the default value is autodetect.

This article permanently updates the link address:

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.