In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Failure scenario
There is an emoji emoji in the user's nickname. When you call jdbc to insert into the mysql database, throw an exception java.sql.SQLException: Incorrect string value:'\ xF0\ x9F\ x90\ x9B'
Cause of failure
Mysql's utf8 encodes up to 3 bytes of a character, but an emoji emoji is 4 bytes, so utf8 does not support storing emoji emoticons. But utf8's superset utf8mb4 can have up to 4 bytes in a character, so it can support the storage of emoji emoticons.
I won't say much. Let's take a look at the detailed introduction.
Solution
one。 Modify database, table, column character sets
Modify database character set
ALTER DATABASE database name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci
Modify table character set
ALTER TABLE table name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
Modify column character set
ALTER TABLE table name CHANGE field name field name the field's original data type CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
The above three kinds can be modified according to their own actual situation.
two。 View mysql configuration variables
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE' collation%'
Notice whether the value of the variable character_set_server is equal to utf8mb4, if not, look at step 3.
three。 Modify mysql configuration file
Here mysql is installed under centos, the configuration file name is my.cnf, and the path is based on the directory where you installed it.
Vim / etc/my.cnf / etc/mysql/my.cnf
My.cnf
Find character_set_server, set its value to utf8mb4, and save exit; try to re-insert to see if there is an error; if you report an error, you may need to restart the mysql service
Service mysqld restart
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.