Java stores emoji emoticons in MySQL

Source: Internet
Author: User

MySQL store emoji emoticons to use the UTF8MB4 character set, which is 4 bytes of storage, the minimum supported version is 5.5.3+, if not, upgrade to a newer version.

Modify the MySQL configuration file

Window directory: mysql/my.iniubuntu16.04 directory:/ETC/MYSQL/CONF.D/MYSQL.CNF configuration client/etc/mysql/mysql.conf.d/mysql.cnf Configure server Other directories: generally in ETC/MYSQL/MY.CNF

Add the following three parts to the MySQL 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 '

Restart MySQL after modifying, check the character set

# mysql-uroot-p# mysql > SHOW VARIABLES WHERE variable_name like ' character_set_% ' OR variable_name like ' collation% ' ;

Results

+--------------------------+--------------------+| variable_name             | Value               |+--------------------------+--------------------+| character_set_client      | utf8mb4             ||  character_set_connection | utf8mb4             | |  character_set_database   | utf8mb4             | |  character_set_filesystem | binary              | |  character_set_results    | utf8mb4             | |  character_set_server     | utf8mb4            | |  character_set_system     | utf8                | |  collation_connection     | utf8mb4_unicode_ci | |  collation_database       | utf8mb4_unicode_ci | |  collation_server         | utf8mb4_unicode_ci |+- -------------------------+--------------------+rows in set  (0.00 sec)

Java Link Configuration

jdbc.driverclass=com.mysql.jdbc.driverjdbc.jdbcurl=jdbc:mysql://localhost:3306/tgb?useunicode=true& characterencoding=utf8&autoreconnect=true&rewritebatchedstatements=truejdbc.user=rootjdbc.password= Jdbc.initialpoolsize=10jdbc.minpoolsize=10jdbc.maxpoolsize=50jdbc.maxidletime= 3600jdbc.testconnectiononcheckout=falsejdbc.testconnectiononcheckin=truejdbc.idleconnectiontestperiod=3600


This article is from the "Yang Chongxin blog" blog, make sure to keep this source http://yangchongxing.blog.51cto.com/1004067/1969794

Java stores emoji emoticons in MySQL

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.