Recently, when the Web project was deployed under centos6.5, the webpage appeared garbled in Chinese, and after excluding PHP, the problem was locked in the MySQL encoding mode.
Here's how to fix it:
First enter the MySQL command line, enter the command: show VARIABLES like ' character_set_% ', the following information will appear
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | Latin1 |
| character_set_connection | Latin1 |
| Character_set_database | Latin1 |
| Character_set_filesystem | binary |
| Character_set_results | Latin1 |
| Character_set_server | Latin1 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
MySQL's default encoding is latin1 instead of UTF8
In general, there are three ways of handling:
1. When creating the database, the default encoding format is UTF8, this method I used before, but did not solve the problem
2. Set the encoding format in the MySQL command line via commands such as:
Set character_set_client = UTF8;
....
This method will fail after restarting MySQL
3. The most fundamental solution is to directly modify the MySQL configuration file, the file path is/etc/my.cnf, into the vim editing interface, make the following changes:
--add under [mysqld]:
Default-character-set=utf8
Character_set_server=utf8
--add under [MySQL]:
Default-character-set=utf8
--add under [Mysql.server]:
Default-character-set=utf8
--add under [Mysqld_safe]:
Default-character-set=utf8
--add under [client]:
Default-character-set=utf8
Restart the MYSQLD service and enter the MySQL command line for show VARIABLES like ' character_set_% ', when the configuration is in effect
+--------------------------+----------------------------+
| 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 | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
In addition, the original database needs to be deleted and re-imported database files, open browser testing, garbled problem resolution
Chinese garbled problem caused by MySQL encoding of Web project in centos6.5 environment