Chinese garbled problem caused by MySQL encoding of Web project in centos6.5 environment

Source: Internet
Author: User
Tags mysql command line

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.