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.
【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!