Home > Database > Mysql Tutorial > What should I do if the Chinese characters are garbled when mysql saves data?

What should I do if the Chinese characters are garbled when mysql saves data?

coldplay.xixi
Release: 2020-09-03 13:14:20
Original
4367 people have browsed it

Solution to Chinese garbled characters when mysql saves data: 1. Set the encoding set related to the client [set names gbk;]; 2. In the [my.ini] configuration file, change [default- Change character-set=utf8] to [=gbk] and restart.

What should I do if the Chinese characters are garbled when mysql saves data?

【Related learning recommendations: mysql tutorial(Video)】

Solution to Chinese garbled characters when mysql saves data:

The problem lies in the current CMD client window, because the current CMD client input GBK encoding is used, and the encoding format of the database is UTF-8. Inconsistent encoding results in garbled characters.

The encoding format of the current CMD client cannot be modified, so the encoding set of connection, client, and results can only be modified to inform the server that the currently inserted data uses GBK encoding, and although the server's database uses UTF-8 encoding, but it can identify the GBK encoded data notified to the server and automatically convert it to UTF-8 for storage. You can use the following statement to quickly set the encoding set related to the client:

set names gbk;

After the setting is completed, the client can insert data or display data. There is a garbled code problem, but we will soon find that this form of setting will only be effective in the current window. When the CMD client is reopened after the window is closed, the garbled code problem will appear again. So, how to make a once and for all setting?

There is a my.ini configuration file in the MySQL installation directory. By modifying this configuration file, you can solve the garbled problem once and for all. 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 time, you only need to change the default encodingdefault-character-set=utf8 Change to default-character-set=gbk and restart the MySQL service.

If you want to know more about programming learning, please pay attention to the php training column!

The above is the detailed content of What should I do if the Chinese characters are garbled when mysql saves data?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template