Let MySQL database support emoji emoticons

Source: Internet
Author: User
Tags mysql code

Problem: The Emoji expression is stored in 4 bytes, so the traditional MySQL utf-8 encoding can only be stored for a maximum of 3 bytes.

FIX: Modify MySQL (5.5.3 or above) encoded as UTF8MB4 to store the emoji table, and set the set names UTF8MB4 otherwise the program writes and reads garbled.

Requirements: MySQL 5.5.3 or more (online said), I did not test, I use MySQL 5.6 pro-test, can be stored.

To modify the MySQL code:

1. OS X System: http://www.cnblogs.com/chenshuo/p/4751855.html

2. Linux System: http://www.cnblogs.com/chenshuo/p/4743144.html

3. Windows Please google Baidu on its own.

Full table coding (lest forget later)

CREATE TABLE`User' (' UID 'varchar( -)CHARACTER SETUtf8 not NULL DEFAULT "', ' email 'varchar( +)CHARACTER SETUtf8DEFAULT NULL, ' username 'varchar( +)CHARACTER SET UTF8MB4 DEFAULT NULL, ' password 'varchar( +)CHARACTER SETUtf8DEFAULT NULL, ' token 'varchar( +)CHARACTER SETUtf8DEFAULT NULL, ' OpenID 'varchar( +)CHARACTER SETUtf8DEFAULT NULL, ' Avatar 'varchar( -)CHARACTER SETUtf8DEFAULT NULL, ' Teamid 'varchar(Ten)CHARACTER SETUtf8DEFAULT '0', ' position 'smallint(6)DEFAULT '0', ' main 'smallint(6)DEFAULT '1', ' Captain 'smallint(6)DEFAULT '0', ' numbers 'smallint(6)DEFAULT '0', ' height 'int( One)DEFAULT '0', ' weight 'int( One)DEFAULT '0',  ` Level`smallint(6)DEFAULT '0', ' Gold 'int( One)DEFAULT '0', ' Points 'int( One)DEFAULT 'Ten', ' phone 'varchar( One)CHARACTER SETUtf8DEFAULT NULL, ' address 'varchar( +)CHARACTER SETUtf8DEFAULT NULL, ' state 'smallint(6)DEFAULT '0', ' follow 'int( One)DEFAULT '0', ' fans 'int( One)DEFAULT '0', ' Createtime 'timestamp NULL DEFAULT Current_timestamp,  PRIMARY KEY(' uid ')) ENGINE=InnoDBDEFAULT charset=utf8mb4 Collate=utf8mb4_bin;

Let MySQL database support emoji emoticons

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.