Home > Database > Mysql Tutorial > [MySQL 04] Command line query garbled problem

[MySQL 04] Command line query garbled problem

黄舟
Release: 2017-02-04 11:47:24
Original
1220 people have browsed it

First, display the garbled characters, mainly Chinese garbled characters:

[MySQL 04] Command line query garbled problem

Step 1: Find the directory where mysql is installed and find the my.ini file;

[MySQL 04] Command line query garbled problem

Step 2: Use Notepad to open the my.ini file and set the default encoding to utf-8:

[MySQL 04] Command line query garbled problem

Step three: Enter in the mysql database cmd: show variables like'%char%';

[MySQL 04] Command line query garbled problem

## Step four: Change the encoding method of the original database:

[MySQL 04] Command line query garbled problem

Step 5: Changed encoding method:

[MySQL 04] Command line query garbled problem

Step 6: Query again:

[MySQL 04] Command line query garbled problem

Several character sets involved in MySQL

character-set-server/default-character-set: Server character set, used by default.

character-set-database: Database character set.
character-set-table: Database table character set.
The priorities increase in sequence. Therefore, generally you only need to set the character-set-server, and do not specify the character set when creating databases and tables. In this way, the character-set-server character set is uniformly used.
character-set-client: The client’s character set. Client default character set. When a client sends a request to the server, the request is encoded in this character set.
character-set-results: Result character set. When the server returns results or information to the client, the results are encoded in this character set.
On the client side, if character-set-results is not defined, the character-set-client character set is used as the default character set. So you only need to set the character-set-client character set.

To process Chinese, you can set both character-set-server and character-set-client to GB2312. If you want to process multiple languages ​​at the same time, set it to UTF8.

About Chinese issues with MySQL

The way to solve the garbled characters is to set the following three system parameters of MySQL to the same characters as the server character set character-set-server before executing the SQL statement. set.

character_set_client: The client’s character set.
character_set_results: Result character set.
character_set_connection: Connection character set.
Set these three system parameters by sending statements to MySQL: set names gb2312

The above is the content of [MySQL 04] command line query garbled problem. For more related content, please pay attention to the PHP Chinese website (www. php.cn)!


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