Linux MySQL 5.5 modified character set encoding for UTF8 (completely solve Chinese garbled problem)

Source: Internet
Author: User
Tags mysql view

One, login MySQL view with show variables like ' character% '; The following character set, which is displayed 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/|
+--------------------------+----------------------------+

II, the simplest perfect modification method, modifies the character set key value in the MySQL my.cnf file ( Note the field details of the configuration ):

1, add Default-character-set=utf8 to the [client] field as follows:

[client]
Port = 3306
Socket =/var/lib/ Mysql/mysql.sock
Default-character-set=utf8

2, add Character-set-server=utf8 to the [mysqld] field as follows:

[mysqld]
Port = 3306
Socket =/var/lib/mysql/mysql.sock
Character-set-server=utf8

3. Add Default-character-set=utf8 to the [MySQL] field as follows:

[MySQL]
No-auto-rehash
Default-character-set=utf8

After the modification is complete, the service MySQL restart restart MySQL services will take effect. Note: The [mysqld] field differs from the [MySQL] field. This is no one on the internet feedback.

Use show VARIABLES like ' character% '; view, found that the database encoding has been changed to UTF8.

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

4, if the above are modified also garbled, then the remaining problem must be on the connection connection layer. The workaround is to execute the following sentence before sending the query (write directly to the front of the SQL file):
SET NAMES ' utf8′;

It is equivalent to the following three-sentence instruction:

SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

Many other methods on the net can not solve this problem completely, this could be solved perfectly!

Related Article

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.