Home  >  Article  >  Database  >  Mysql table does not display Chinese, what should I do if it is garbled?

Mysql table does not display Chinese, what should I do if it is garbled?

藏色散人
藏色散人Original
2020-11-06 10:23:012987browse

Mysql table does not display Chinese and the solution is garbled: first check the encoding method of the database; then edit and open the my.ini file; then modify the content to "default-character-set=utf8"; finally restart the database That’s it.

Mysql table does not display Chinese, what should I do if it is garbled?

Recommended: "mysql video tutorial"

Solution to Chinese garbled Chinese data table in mysql

When inserting data into the mysql database, the data (Chinese characters) is garbled:

After changing the encoding of the database and data table to UTF-8, the data is still garbled.

Mysql table does not display Chinese, what should I do if it is garbled?

The default encoding of Mysql is Latin1, which does not support Chinese. Therefore, if you want mysql to support Chinese, you need to change the default encoding of the database to gbk or utf8.

1. Check the encoding method of the database

mysql>show variables like 'character%';

Mysql table does not display Chinese, what should I do if it is garbled?

The above various character settings must be consistent, but simply setting the encoding format for the database and data table cannot Completely solve the garbled code problem. I solved the garbled code problem by setting all the character encodings mentioned above to utf8.

Explain the above information:

  | character_set_client:客户端请求数据的字符集(编码方式)
  | character_set_connection:从客户端接收到数据,再传输的字符集(建立连接使用的编码)
  | character_set_database:默认数据库的字符集,无论默认数据库如何改变,都是这个字符集;如果没有默认数据库,那就使用 character_set_server 指定的字符集,
                            这个变量建议由系统自己管理,不要人为定义。
  | character_set_results:结果集的字符集
  | character_set_server:数据库服务器的默认字符集
  | character_set_system:这个值总是utf8,不需要设置,是存储系统元数据的字符集

When the values ​​of the above variables are inconsistent or display garbled characters, you can modify them through the following commands:

mysql> SET character_set_client = utf8; 
mysql> SET character_set_results = utf8;  
mysql> SET character_set_connection = utf8;

2. Find MySQL5.0 Edit and open the my.ini file in the installation directory and modify it to:

[client]
port=3306
default-character-set=utf8
[mysql]
default-character-set=utf8
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8

3. Restart the database.

The above is the detailed content of Mysql table does not display Chinese, what should I do if it is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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