The records of this blog are operated on Linux
The project needs to log in from obtaining authorization, and in this process, there was an error saving the emoji emoticons to the MySQL database.
The usual Baidu, learned that the UTF8 character set is MySQL only supports 1-3-byte characters, and the expression needs 4 bytes, so MySQL provides a utf8mb4 character set, in support of 4 bytes at the same time can be perfectly compatible with UTF8, without our worries.
Baidu Most of the steps are like this, 1-3 steps can use the command can also use tools (such as Navicat) to complete.
1: Modify the database Character set:
(1) Command mode: ALTER database name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
(2) Tool mode: Select the specified database, mail Select Database properties, modify the character set and collation as follows:
2: Modifying the character set of a database table
(1) Command mode: First switch to the database operated by step 1, then execute the command: ALTER table name CONVERT to CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
(2) Tools: Open the database, select the table you want to manipulate, right-click the Design table, select options, select the character set and collation as follows:
3: Modifying the character set of a column
(1) Command mode: ALTER table name change field name the field's original data type CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Example: ALTER TABLE user change name TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
(2) Tool mode: Select the table to be manipulated, right-select the design table, select the specified field, modify the character set and collation as follows:
4: Modify the My.cnf file (Windows is a My.ini file)
Edit the file and add the following:
[Client]default-character-set=utf8mb4[mysqld]character-set-client-handshake = Falsecharacter-set-server = Utf8mb4collation-server = utf8mb4_unicode_ciinit_connect= ' SET NAMES utf8mb4 ' [mysql]default-character-set=utf8mb4
5: Finally, I need to restart MySQL.
The above method is suitable for the common use of MySQL expression problem. If you use MyBatis to do persistent layer operations, you may encounter a more pit problem, which you have configured, and still will not succeed. Find a lot of information, finally found a blogger answer, connection pool configuration can add such a configuration:
<property name= "Connectioninitsqls" ><list><value>set names utf8mb4</value></list> </property>
Finally, of course, it's a perfect solution.
Would like to paste the last link to the blogger ~ but found all over the history has not been able to find, hate forgotten collection ~ ~ ~
If you can not solve the problem by the above way, refer to the following question Jian Shubo friend's article: HTTPS://WWW.JIANSHU.COM/P/B0F5EB5D7CC3
He uses a compromise way of storing the contents of the storage, after the extraction and decoding, relatively troublesome, but also a solution
SSM frame +mysql Save emoji expression