In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to change the MySQL database code to utf8mb4, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Utf8mb4 coding is a superset of utf8 coding, compatible with utf8, and can store 4 bytes of emoji characters.
The advantage of using utf8mb4 coding is that when storing and obtaining data, there is no need to consider the encoding and decoding of emoji characters.
Change the database encoding to utf8mb4:
1. Version of MySQL
The minimum mysql version of utf8mb4 supports version 5.5.3. If not, upgrade to a newer version.
2. MySQL driver
5.1.34 available, with a minimum of 5.1.13
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE' collation%'
3. Modify MySQL configuration file
Modify mysql configuration file my.cnf
The my.cnf is usually in the etc/mysql/my.cnf location. When you find it, please add the following in the following three sections:
[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4
Conspicuous ground
[mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4'
4. Restart the database and check for variables
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE' collation%'
It doesn't matter what collation_connection, collation_database and collation_server are.
But you have to make sure
System variable description
Character_set_client (character set used by client source data)
Character_set_connection (connection layer character set)
Character_set_database (the default character set for the currently selected database)
Character_set_results (query result character set)
Character_set_server (default internal operation character set)
These variables must be utf8mb4.
5. Configuration of database connection
In the database connection parameters:
CharacterEncoding=utf8 is automatically recognized as utf8mb4, or it can be automatically detected without this parameter.
And autoReconnect=true must be added.
6. Convert the database and built tables to utf8mb4 as well
Change the database code: ALTER DATABASE caitu99 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
Change table encoding: ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8mb4 COLLATEutf8mb4_general_ci
You can also change the encoding of the column if necessary
Thank you for reading this article carefully. I hope the article "how to change the code of MySQL database to utf8mb4" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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