Home > Database > Mysql Tutorial > Detailed explanation of the Chinese garbled problem in mysql database

Detailed explanation of the Chinese garbled problem in mysql database

小云云
Release: 2017-12-08 13:05:49
Original
1513 people have browsed it

This article mainly introduces relevant information on the detailed explanation of the Chinese garbled problem in mysql database. Friends in need can refer to it.

When inserting a piece of data with Chinese characters into the MySQL database, the shape is insert into employee values(null,'Zhang San','female','1995-10-08','2015-11 -12','Sales',2000,'What a good employee! '); When garbled characters appear, you can use the statement show variables like 'character%'; to view the relevant encoding set of the current database. .

As you can see from the above figure, MySQL uses character sets in six places, namely: client, connection, database, results, server, and system. Among them, related to the server: database, server, system (can never be modified, it is utf-8); related to the client: connection, client, results.

##resultsWhen the database returns to the client The character set to use. If not specified, the server's default character set will be used.

client

is The character set used by the client.

connection

## is the character set setting for connecting to the database Type, if the program does not specify the character set type used to connect to the database, the server-side default character set setting will be used.

##database

is a library in the database server The character set setting used, if not specified when building the database, will use the character set setting specified when the server is installed.

server

is the default character set setting specified during server installation.

system

## is the character set used by the database system set up.


After understanding the above information, let’s analyze the cause of the garbled characters. The problem lies in the current CMD. In the client window, because the current CMD client input uses GBK encoding, 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. Although the server's database uses UTF-8 encoding, it can be recognized Notify the server side of GBK encoded data 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;

It can be solved after the setting is completed There is a garbled problem when inserting data or displaying data on the client, but we will soon find that this form of setting will only be effective in the current window. When the window is closed and the CMD client is reopened, the garbled problem will appear again; then, how to make a What about a set-and-forget setup? 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 encoding default-character Change -set=utf8 to default-character-set=gbk and restart the MySQL service.

Have you learned it? Hope it can solve the urgent need.


Related recommendations:

Summary of solutions to Chinese garbled characters in mysql database

##Solutions to Chinese garbled characters in PHP connection to MySQL database_ PHP tutorial

How to solve Chinese garbled characters in mysql database. Modifying the character encoding in the configuration file has no effect

The above is the detailed content of Detailed explanation of the Chinese garbled problem in mysql database. 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