MySQL Database character Set settings

Source: Internet
Author: User

1. Operating system: CentOS6.6

2. Database system: Mysql

3. Task: Solve the problem of garbled data

1) Change the character set of the client GBK

Client character set setting, set names GBK, this ensures that the inserted Chinese, does not appear garbled, on the execution of the set names GBK, the previously inserted Chinese invalid.

Description: Typically the following several character sets are the same and character_set_database as the database's character set to ensure that the write data is output correctly.

mysql> set names GBK; # Change the character set of the client GBK

Query OK, 0 rows Affected (0.00 sec)

Mysql> Show variables like ' character_set% ';

+--------------------------+----------------------------+

| variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | GBK # Client Character Set               |

| character_set_connection | GBK # Connection Character Set                  |

| character_set_database |GBK # Database Character Set                     |

| Character_set_filesystem | binary |

| character_set_results | GBK # returns the result character set       |

| character_set_server | GBK # Server Character Set                     |

| Character_set_system | UTF8 |

| Character_sets_dir | /usr/share/mysql/charsets/|

+--------------------------+----------------------------+

8 rows in Set (0.00 sec)

2) Change the configuration of the service-side character set:

in the my.cnf in the configuration file [Mysqld] under the module add Word set configuration, after the entry into force, the creation of the database and table by default is the character set of this setting.

[Mysqld]

Datadir=/var/lib/mysql

Socket=/var/lib/mysql/mysql.sock

User=mysql

# Disabling Symbolic-links is recommended to prevent assorted security risks

Symbolic-links=0

DEFAULT-CHARACTER-SET=GBK # add a row to change the character set on the server side

[Email protected]/]# service mysqld restart

stop mysqld                                                  [ ]

is starting mysqld :

Mysql> Show variables like ' character_set% ';

+--------------------------+----------------------------+

| variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | Latin1 |

| character_set_connection | Latin1 |

| Character_set_database |   GBK | #更改成了gbk字符集

| Character_set_filesystem | binary |

| Character_set_results | Latin1 |

| Character_set_server |   GBK | #更改成了gbk字符集

| Character_set_system | UTF8 |

| Character_sets_dir | /usr/share/mysql/charsets/|

+--------------------------+----------------------------+

8 rows in Set (0.01 sec)

3) or specify a character set when logging in:

[Email protected] mysql]# MYSQL–UROOT–P–DEFAULT-CHARACTER-SET=GBK

[Email protected] mysql]# mysql-uroot-p-s/var/lib/mysql/mysql.sock--DEFAULT-CHARACTER-SET=GBK;

This article is from the "Linux~dba~mba" blog, make sure to keep this source http://sky9896.blog.51cto.com/2330653/1605113

MySQL database character set settings

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.