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