Modify the default encoding method of the mysql database _ MySQL

Source: Internet
Author: User
Modify the default encoding method of the mysql database. modify the default encoding method of the mysql database.

Modify the my. ini file

Add

Default-character-set = gb2312

Set Database character sets

Alter database da_name default character set 'charset'

1) set the database encoding/etc/my. cnf

[Mysqld]

Default-character-set = gbk

...

[Client]

Default-character-set = gbk

---------------------------------------

2) export by character set

$ Mysqldump-u root-p dbname-default-character-set = gbk> a. SQL;

3) view the encoding of the SQL file

[Root @ localhost gethtml] # file a. SQL

A. SQL: UTF-8 Unicode...

[Root @ localhost gethtml] # iconv-f UTF-8-t gbk a. SQL> a2. SQL

[Root @ localhost gethtml] # file a2. SQL

A2. SQL: Non-ISO extended-ASCII English text is now gbk encoded.

3) import

View database service and client character sets

Mysql> status;

Server characterset: gbk

Db characterset: gbk

Client characterset: latin1

Conn. characterset: latin1

Mysql> set names 'gbk '; //

Mysql> status;

Server characterset: gbk

Db characterset: gbk

Client characterset: gbk

Conn. characterset: gbk

In this case, data can be exported to mysql> source a. SQL;

----------------------------

Set a database separately: alter database testdb character set utf8;

Check the encoding supported by mysql:

Show character set;

You can run the following two commands to view the character set and sorting method settings of the system:

Mysql> show variables like "character_set _ % ";

LINUX:

1) export data [root@www.cnscn.org ~] $ Mysqldump-u root-p dbname-default-character-set = gbk> base_user. SQL;

2) view the exported SQL file encoding

Root@www.cnscn.org ~ $ File base_user. SQL

Base_user. SQL: UTF-8 Unicode text, with very long lines

3) convert to the encoding to use [root@www.cnscn.org ~] $ Iconv-f UTF-8-t gbk base_user. SQL> base_user_gbk. SQL

4) connect to the database and view the encoding of the current database

Root@www.cnscn.org ~ $ Mysql-uroot

Mysql> use testdb;

Mysql> status;

Server characterset: latin1

Db characterset: gbk

Client characterset: latin1

Conn. characterset: latin1

5) set the encoding to mysql> set names 'gbk ';

6) view the current encoding

Mysql> status;

Server characterset: latin1

Db characterset: gbk

Client characterset: gbk

Conn. characterset: gbk

7) import the mysql> source base_user_gbk. SQL file converted to gbk;

Source: modify the default encoding method of the mysql database

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.