- 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