Linux set MySQL database character set UTF8

Source: Internet
Author: User

MySQL Chinese garbled solution: the MySQL database encoding unified UTF8

To view the database encoding:

Show variables like ' character% ';

Edit/ETC/MY.CNF

[mysql]default-character-set=utf8[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security Riskssymbolic-links=0default-character-set = Utf8character_set_server = Utf8#lower_case_table_names=1  ignoring case [mysqld_safe]log-error=/var/log/ Mysqld.logpid-file=/var/run/mysqld/mysqld.piddefault-character-set = Utf8[mysql.server]default-character-set = Utf8[client]default-character-set = UTF8

  

After the modification is complete, service MySQL restart restart the MySQL services to take effect. Note: The [mysqld] field differs from the [MySQL] field.

If the above are modified and 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;

Execute show variables like ' character% ' as follows to illustrate the success of the modification

Mysql> Show variables like ' character% '; +--------------------------+----------------------------+| 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/|+--------------------------+----------------------------+8 rows in Set (0.00 sec)

  

Linux set MySQL database character set UTF8

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.