linux--enables MySQL to support Chinese

Source: Internet
Author: User

make MySQL Support Chinese

Welcome reprint, please keep the source: Zcshou Http://blog.sina.com.cn/zcshou

MySQL 4.1and later versions, the support for character sets(Character Set support)there are two aspects: character Set (Character set)and sort the way (Collation). Support for character sets is refined to four levels: Server(server), the database(database), Data Sheet(table)and Connection(Connection).

First, login MySQL , using SHOW VARIABLES like ' character% '; View the character set currently in use , as shown below:

Character_set_database and the Character_set_server The default character set is latin1 .

Second, the simplest perfect modification method, modify MySQL of the my.cnf character Set key values in the file (note the field details of the configuration):

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

[Client]

Port = 3306

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

Default-character-set=utf8

2 , in [Mysqld] in the field, add the following red three sentences, as follows:

[Mysqld]

Port = 3306

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

Default-storage-engine=innodb

Character-set-server=utf8

Collation-server=utf8_general_ci

3 , in [MySQL] field to add Default-character-set=utf8 , as follows:

[MySQL]

No-auto-rehash

Default-character-set=utf8

after the modification is complete, Service MySQL Restart Restart MySQL The service will take effect. Note: In newer versions of the mysq in which [Mysqld] Fields and [MySQL] The fields are different .

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

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 ';

5 , using Show CREATE DATABASE Database name ; View the encoding for the specified database, as follows:

To modify the encoding for the specified database:

Mysql>user MyDB;

Mysql>alter database mydb character set UTF8;

Use Show CREATE TABLE Table name ; view the encoding format for the table. as follows:

set the default encoding to UTF8 :

Set names UTF8;

setting up the database db_name default is UTF8:

ALTER DATABASE ' db_name ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;

Setting up Tables Tb_name The default encoding is UTF8:

ALTER TABLE ' tb_name ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;

welcome reprint, please keep the source: Zcshou        Http://blog.sina.com.cn/zcshou

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.