Mysql character set character_set_client = binary in gbk

Source: Internet
Author: User
Today, when we were dealing with bugs, we found another strange problem. when we set mysql encoding to gbk, we found the created table, when the table structure, whether it is a field or table structure description, is Chinese, the table structure description is garbled. After troubleshooting that it was originally created by the charact mysql link, you can set the encoding as follows:
The code is as follows:
Mysql_query ("SET character_set_connection = ". $ GLOBALS ['charset']. ", character_set_results = ". $ GLOBALS ['charset']. ", character_set_client = binary", $ this-> link );

However, the structure description of the created table is garbled:
The code is as follows:
Mysql> show create table nw_admin_config \ G
* *************************** 1. row ***************************
Table: nw_admin_config
Create Table: create table 'NW _ admin_config '(
'Name' varchar (30) not null default ''comment' ������ ',
'Namespace' varchar (15) not null default 'global' comment' �� ���� ',
'Value' text comment' �� COMMENT ',
'Vtype' enum ('string', 'array', 'object') not null default 'string' comment' �������� ',
'Description' text comment' �� ',
Primary key ('namespace', 'name ')
) ENGINE = MyISAM default charset = gbk COMMENT = '�� n'

After investigation, we found that character_set_client = binary caused the following:

The code is as follows: $ targetDb-> query ("set names '{$ charset }'");

The code is as follows:
Mysql> show create table nw_admin_config \ G
* *************************** 1. row ***************************
Table: nw_admin_config
Create Table: create table 'NW _ admin_config '(
'Name' varchar (30) not null default ''comment' configuration name ',
'Namespace' varchar (15) not null default 'global' comment' configure namespace ',
'Value' text comment' cache value ',
'Vtype' enum ('string', 'array', 'object') not null default 'string' COMMENT 'configuration value type ',
'Description' text comment' configuration introduction ',
Primary key ('namespace', 'name ')
) ENGINE = MyISAM default charset = gbk COMMENT = 'website configuration table'

However, if the character set I set is UTF8 and the table structure is utf8, even if the above character_set_client = binary is used, the table structure description is normal:
The code is as follows:
Mysql> show create table nw_admin_config \ G
* *************************** 1. row ***************************
Table: nw_admin_config
Create Table: create table 'NW _ admin_config '(
'Name' varchar (30) not null default ''comment' configuration name ',
'Namespace' varchar (15) not null default 'global' comment' configure namespace ',
'Value' text comment' cache value ',
'Vtype' enum ('string', 'array', 'object') not null default 'string' COMMENT 'configuration value type ',
'Description' text comment' configuration introduction ',
Primary key ('namespace', 'name ')
) ENGINE = MyISAM default charset = utf8 COMMENT = 'website configuration table'

The strange thing is that garbled characters exist only in the description of the table structure, but the Chinese characters of the inserted data are still normal ~

I checked character_set_client = binary on the Internet and said "most of them are set to solve the garbled problem", but I don't know. this table structure description turns out to be garbled. What is the purpose of this? Why are the table structures different?

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.