MySQL: Setting character set UTF8MB4 supports emoji characters

Source: Internet
Author: User

Why do you want to set the database charset to UTF8MB4? UTF8 used to be all the time?
The answer is here: UTF8 for Internet interactions that do not use mobile devices, UTF8MB4 is suitable for the current mobile device Internet development, as mobile devices often have emoji (emoji) storage, which consumes 4 bytes of storage space, while UTF8 is 3 bytes, so that With 3 bytes to store 4 bytes of things, it is obvious that there is no way, will error, so to use UTF8MB4, and UTF8MB4 is compatible with UTF8, then there is no reason not to use UTF8MB4 character set.

Describes setting the character set for MySQL:

1 Install MySQL in ubuntu (password own settings)

sudo apt-get install mysql-serversudo apt-get install mysql-clientsudo apt-  Get Install Libmysqlclient-dev

2 accessing MySQL, viewing information

/etc/mysql/mysql.conf.d/mysqld.cnf

Can see my MySQL version is 5.7, UTF8MB4 has a use limit, MySQL version must be more than 5.5, we need to note that I currently use the Ubuntu system is 16.04. The current MySQL character set is configured as in the table above, and our aim is to change to UTF8MB4.

3 MySQL configuration file found, available commands

sudo find/-name my.cnf

4 Modifying a configuration file

[Client] default-character-Set = Utf8mb4[mysql]default-character-Set =  Utf8mb4[mysqld]character-set-client-handshake = falsecharacter-set-server =  Utf8mb4collation-server = utf8mb4_unicode_ciinit_connect='SET NAMES utf8mb4 '

or direct execution:


ALTER Table Apps modify name varchar (character) set UTF8MB4 collate utf8mb4_unicode_ci;
ALTER table Apps charset=utf8mb4;
Set Names UTF8MB4

MySQL: Setting character set UTF8MB4 supports emoji characters

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.