Home >Operation and Maintenance >CentOS >Chinese garbled characters appear in mysql under centos system

Chinese garbled characters appear in mysql under centos system

王林
王林Original
2020-03-20 14:29:462195browse

Chinese garbled characters appear in mysql under centos system

1. Log in to MySQL to view the character set using SHOW VARIABLES LIKE 'character%';, the display is as follows:

Chinese garbled characters appear in mysql under centos system

character_set_database and The default character set of character_set_server is still latin1.

(Recommended tutorial: centos usage tutorial)

Solution:

Just modify the character set key value in the my.cnf file of mysql .

1. Add default-character-set=utf8 in the [client] field, as follows:

[client]
default-character-set=utf8

2. Add character-set-server= in the [mysqld] field utf8, as follows:

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8

3. Add default-character-set=utf8 in the [mysql] field, as follows:

[mysql]
no-auto-rehash
default-character-set=utf8

After the modification is completed, execute the command service mysql restart Just restart the mysql service.

Note: There is a difference between the [mysqld] field and the [mysql] field.

Recommended related video tutorials: linux video tutorial

The above is the detailed content of Chinese garbled characters appear in mysql under centos system. 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