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

The solution of Chinese garbled code when storing data in mysql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the solution to Chinese garbled code when storing data in mysql. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Solutions to Chinese garbled when mysql stores data: 1. Set the client-related code set [set names gbk;]; 2. In the [my.ini] configuration file, change [default-character-set=utf8] to [= gbk] and restart it.

Solution to Chinese garbled code when storing data in mysql:

The problem lies in the current CMD client window, because the current CMD client input uses GBK encoding, while the database encoding format is UTF-8, which leads to garbled codes due to inconsistent coding.

However, the coding format of the current CMD client can not be modified, so we can only modify the coding set of connection, client and results to tell the server that the data currently inserted is encoded by GBK. Although the database of the server uses UTF-8 coding, it can identify the GBK encoded data of the notification server and automatically convert it into UTF-8 for storage. You can use the following statement to quickly set the client-related code set:

Set names gbk

After the setting is completed, you can solve the problem of garbled code when the client inserts or displays data, but we will soon find that this form of setting will only be valid in the current window, and there will be garbled problem when the CMD client is reopened after the window is closed; so, how to make a setting once and for all?

There is a my.ini configuration file in the MySQL installation directory, and the garbled problem can be solved once and for all by modifying this configuration file. In this configuration file, [mysql] is related to the client configuration and [mysqld] is related to the server configuration. The default configuration is as follows:

[mysql]

Default-character-set=utf8

[mysqld]

Character-set-server=utf8

At this point, you only need to change the default encoding default-character-set=utf8 to default-character-set=gbk, and restart the MySQL service.

This is the end of the solution to Chinese garbled code when saving data in mysql. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

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