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;