Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the character set utf8 to utf8mb4 in MySQL

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how to change the character set utf8 to utf8mb4 in MySQL. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.

[client] default-character-set=utf8mb4 [mysqld] character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4' skip-character-set-client-handshake = true [mysql] default-character-set=utf8mb4

Recommendations when using the MySQL character set

Try to explicitly indicate the character set used when establishing a database / table and performing database operations, rather than relying on the default settings of MySQL, otherwise MySQL upgrades may cause great trouble

Although the problem of garbled code can be solved in most cases when using latin1 for both database and connection character sets, the disadvantage is that the SQL operation cannot be carried out on a character-by-character basis. In general, setting the database and connection character set to utf8 is a better choice.

When using mysql C API, set the MYSQL_SET_CHARSET_NAME property to utf8 with mysql_options immediately after initializing the database handle, so that you do not have to specify the connection character set explicitly with the SET NAMES statement, and the connection character set will be reset to utf8 when you reconnect a disconnected persistent connection with mysql_ping

For mysql PHP API, the total running time of page-level PHP programs is relatively short, so you can explicitly set the connection character set with SET NAMES statement after connecting to the database; but when using persistent connections, be careful to keep the connection open and explicitly reset the connection character set with SET NAMES statement after disconnection and reconnection.

The above is how to change the character set utf8 to utf8mb4 in MySQL. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report