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
Table of contents Introduction to stored procedur...
This article shares the specific code of jQuery t...
This article introduces Nginx from compilation an...
The method found on the Internet works The footer ...
Last time we talked about some SQL query optimiza...
This article example shares the specific code for...
Design the web page shown above: <!DOCTYPE htm...
The specific code is as follows: <div id="...
Starting from this section, we will explain the i...
Table of contents 1. Front-end leading process: 2...
Recently, I made a function similar to shake, usi...
Linux File System Common hard disks are shown in ...
0. What is a tag? XML/HTML CodeCopy content to cl...
Copy code The code is as follows: <div style=&...
Table of contents Step 1: Install node_modules in...