Home > Database > Mysql Tutorial > body text

Detailed explanation of the solution to the Chinese garbled problem in Mysql5.7

黄舟
Release: 2017-03-17 13:30:35
Original
1659 people have browsed it

When using mysql5.7, you will find that garbled characters will appear after writing Chinese to the database through the web end. However, if you directly operate the SQL statement in the databaseAfter inserting data, the Chinese will be displayed normally. This problem How to solve it? The editor will share the solution with you below

When using mysql5.7, you will find that garbled characters will appear after writing Chinese into the database through the web side, but when you directly operate the SQL statement in the database After inserting data, Chinese characters are displayed normally. How to solve this problem? The data encoding process and principles of MySQL will not be explained here. If you are interested, you can Baidu it yourself.

Let’s directly use the following operations to solve the problem:

1. Open the mysql console and enter the command show variables like 'character%';

The display is as follows:

 +--------------------------+-------------------------------------------+
| Variable_name      | Value                   |
+--------------------------+-------------------------------------------+
| character_set_client   | latin1                  |
| character_set_connection | latin1                  |
| character_set_database  | utf8                   |
| character_set_results  | latin1                  |
| character_set_server   | utf8                   |
| character_set_system   | utf8                   |
| character_sets_dir    | C:\MySQL\MySQL Server 5.0\share\charsets\ |
+--------------------------+-------------------------------------------+
Copy after login

2. Modify the my.ini file

 [client]

  default-character-set=utf8

  [mysqld]
  default-storage-engine=INNODB
  character-set-server=utf8
  collation-server=utf8_general_ci
Copy after login

3. After restarting, use the command in the first step to view, as follows:

  +--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
Copy after login

Also the default character setof character_set_database and character_set_server is still latin1.

4. Enter the command: set names utf8;

After restarting, use the first step command to view:

+--------------------------+------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\wamp64\bin\mysql\mysql5.7.9\share\charsets\ |
+--------------------------+------------------------------------------------+
Copy after login

Except character_set_filesystem is binary, Others are all utf8,

In this way, if the encoding is also set to utf8 on the web side, it can be input into the database normally.

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