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

What if there are Chinese garbled codes in mysql database?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article is mainly to tell you briefly what to do when Chinese garbled codes appear in mysql database. You can look up the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article on how to do Chinese garbled codes in mysql database can bring you some practical help.

When inserting a piece of data such as insert into employee values with Chinese into the MySQL database (null,' Zhang San', 'female','1995-10-08', 'female','1995-10-08' is a good employee!) When garbled occurs, you can use the statement show variables like 'character%'; to view the relevant code set of the current database.

From the figure above, you can see that MySQL uses six character sets: client, connection, database, results, server, and system. It is related to the CVM side: database, server, system (can never be modified, that is, utf-8); related to the client: connection, client, results.

Client

The character set used for the client.

Connection

Set the type of character set for connecting to the database. If the program does not specify the type of character set used to connect to the database, it is set according to the default character set on the CVM.

Database

Set the character set used by a library in the database CVM. If it is not specified when building the database, the character set specified during the installation of the CVM will be used.

Results

Set the character set used when the database is returned to the client. If not specified, use the default character set of the CVM.

Server

The default character set specified during the installation of the CVM.

System

Sets the character set used by the database system.

After understanding the above information, let's analyze the causes of garbled codes. 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, resulting in garbled codes due to inconsistent coding. The encoding format of the current CMD client cannot be modified, so the encoding sets of connection, client and results can only be modified to inform the CVM that the data currently inserted is encoded by GBK. Although the database of the CVM uses UTF-8 encoding, it can identify the GBK encoded data of the notification CVM 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 client configuration, and [mysqld] is related to CVM 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.

Mysql database Chinese garbled how to do first to tell you here, for other related issues you want to know can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

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