This article describes the support and problem solving methods of MySQL Java server for emoji. Share with you for your reference, the details are as follows: Problem Description The microblog data captured by the bottom layer is stored in MySQL. Some data fails to be stored. After checking Tomcat, the core error information is as follows:
Cause Analysis
【Note】
Workaround Filter special emoticons content = content.replaceAll("[\\x{10000}-\\x{10FFFF}]", ""); // Simple and crude, not humane Upgrading the database character set 1. The MySQL version supported by utf8mb4 is 5.5.3+. If MySQL is lower than this version, please upgrade it first. 2. Modify the database, table and column character set 3. Modify the MySQL configuration file my.cnf (my.ini for Windows). my.cnf is generally in the etc/mysql/ directory. After finding it, add the following content in the following three parts: [client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect = 'SET NAMES utf8mb4' 4. Restart mysql and check the character set Enter in the mysql command line: SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%'; Character set before restart Character set after restart 【Note】
After completing the above 4 steps, use the MySQL client navicat to manually add Emoji expressions ⛄ to the table. If it can be saved successfully, it means that the database has been upgraded successfully. For the specific differences between these character set configurations, refer to In-depth MySQL character set settings 5. Check the server-side db configuration file // The links used when configuring spring are as follows: url="jdbc:mysql://localhost:3306/gzhou?allowMultiQueries=true&useUnicode=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&autoReconnectForPools=true&failOverReadOnly=false&maxReconnects=10" // If characterEncoding=utf8mb4, an error message will be displayed when inserting data. Caused by: java.sql.SQLException: Unsupported character encoding 'utf8mb4' // Remove characterEncoding or characterEncoding=utf8 Emoji In the Android system, Sogou and Baidu input methods come with built-in Emoji expressions. 【Note】 If the Emoji symbols between systems are incompatible, only squares will be seen; Readers who are interested in more MySQL-related content can check out the following topics: "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills". I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Method of Vue component document generation tool library
>>: How to deal with the problem that the file is deleted but the space is not released in Linux
summary Docker-compose can easily combine multipl...
Table of contents How to rename MySQL database Th...
This article mainly introduces why v-if and v-for...
Mysql left join is invalid and how to use it When...
Table of contents 1. The direction of this in the...
Table of contents 1. Create a stored function 2. ...
Questions about select elements in HTML have been...
Use text-align, margin: 0 auto to center in CSS W...
1. Introduction By enabling the slow query log, M...
This article shares with you the specific code of...
I was recently writing a lawyer recommendation we...
It has always been very difficult to achieve wave...
Syntax format: row_number() over(partition by gro...
Table of contents 01-Event Bubbling 1.1- Introduc...
Table of contents Logical Layering Separate busin...