Modify MySQL database Encoding

Source: Internet
Author: User

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 imported.
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 be used
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 it to the required encoding.
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 file converted to GBK
Mysql> source base_user_gbk. SQL;

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.