MySQL Support emoji Emoticons

Source: Internet
Author: User

    1. Insert emoji expression in MySQL, error occurred:

Java.sql.SQLException:Incorrect string value: ' \xf0\x9f\x98\x8a ' for column ' content ' at row

The reason is that the current MySQL character set is Utf-8, up to 3 bytes, and the emoji expression takes 4 bytes to represent. So the insert error is caused.

The general approach is to change the character set to UTF8MB4

2. Utf8mb4 such a character set requires MySQL 5.5 to support, then my version of Micro 5.1, so I went to the official website under the 5.6 Yum package, upgrade themselves.

The upgrade went well, 1. View Mysql:rpm-qa on Run | grep -I. mysql

2. Stop the mysqld service, delete the old mysql:yum remove MySQL mysql-*; config file I have not deleted, so the new can be used

3. Install a new MYSQL:RPM-IVH (Devel client Server three RPM package)

4. Enter Mysql>, all data are in, execute Mysql_upgrade-u root-p

End of upgrade

3. Changing the character set

  • MY.CNF: After upgrade only/etc/my.cnf.rpmsave, rename it to my.cnf, add it in it, and then service restart MySQL:
    [mysqld]character- set-server=utf8mb4[mysql]default-character-set=utf8mb4
  • Change the character set of the datebase,table,column (in fact I only use the next two, the datavase does not change and does not seem to affect):
    # foreachDatabase:ALTER DATABASEdatabase_nameCHARACTER SET =UTF8MB4 COLLATE=utf8mb4_unicode_ci;# foreachTable:ALTER TABLEtable_nameCONVERT  to CHARACTER SETutf8mb4 COLLATE utf8mb4_unicode_ci;# foreachcolumn:ALTER TABLETABLE_NAME Change COLUMN_NAME column_nameVARCHAR(191)CHARACTER SETUTF8MB4 COLLATE utf8mb4_unicode_ci;

  • Verify that the changes are in effect and see the MySQL and field character sets, respectively:
    MySQL>like'%char%'mysql> full from TableName;

  • Reference:

Http://www.cnblogs.com/vincentchan/archive/2012/09/25/2701266.html

MySQL 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.