Introduction to MySQL garbled processing and Character Set

Source: Internet
Author: User

We often encounter some cases of inserting Chinese characters into the MySQL database, but when we select them, we find garbled characters. For example, we enter and exit such a record from Table a: I

  a (,);

When you access it, you may find that the result is changed to as shown in:


To solve the character set problem, you must first know what character sets are used in the current system, database, table, client, and so on, and what character sets are supported by the system. The following describes some statements for obtaining relevant information:

1. View All character sets supported by the database

Show; or show;

2. Check the current status, including the character set settings:

Status or \ s

3. View System Character Set settings, including all character set settings:

show variables  ;

How to get the result:

4. View Character Set settings in the data table:

show  columns  tablename;

Tablename \ G;

5. view the database code:

show   dbname;

After knowing how to find the relevant information about the character set, we need to know how to match the corresponding character set for the object when creating the specified object.

1. server level:

When installing MySQL, you can set the default encoding format of the server, or modify character_set_server = utf8 in [mysqld] to set the character_set_server value.

2. Database level:

      utf8;

3. Table-level:

   ``.`tb_name` (id ()  ,name () ) ENGINEInnoDB  CHARSETutf8;

It can be seen that the default Character Set of the defined table is utf8. Even if character_set_database is gbk, the columns in the table are not utf8

4. Column level:

   ``.`tb_name` (   id ()  ,   name ()   utf8 );

As you can see, the default Character Set of the entire table is gbk, so columns without the specified character set use the default character set. If the name of the character set column is specified, the specified character set utf8 is used.

If you have already created an object, what should you do. We should modify the character set for the specified object.

For a connection, you can use:

 NAMES  

NAMES

Equivalent

 character_set_client  character_set_results  character_set_connection  charset_name;

You can also modify the configuration file to add default-character-set = utf8 under [mysql] and configure it to the desired character set. (I tried to configure it in my. ini, but it was ineffective. I don't know if it was overwritten by the character set that the client wanted ?)

          COLLATE collation_name]

The simplest way is to directly change the [mysqld] field in the my. ini configuration file, add character-set-server = gbk, and restart mysqld to change the character set you want.

   

 {    } (     

For example:

 ( 

 

  • References:

MySQL Character Set Support: http://dev.mysql.com/doc/refman/5.6/en/charset.html

Mysql common view library, table character set command: http://bjlfp.blog.163.com/blog/static/773684612012298455765/

The problem of Chinese garbled characters when MySQL inserts data: http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.html

 

 

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.