[mysqld]
default-character-set=gbk
...
[client]
default-character-set=gbk
---------------------------------------
2)按字符集导出
$mysqldump -u root -p dbname --default-character-set=gbk > a.sql;
3)查看SQL文件的编码
[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 这时已经是gbk的编码了
3)导入
查看数据库服务和客户端字符集
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
这时才能导数据
mysql> source a.sql;
----------------------------------------------------------------------------------
单独设置某个数据库:
alter database testdb character set utf8;
查看mysql支持的编码:
show character set;
[root@www.cnscn.org ~]$ mysqldump -u root -p dbname --default-character-set=gbk > base_user.sql;
[root@www.cnscn.org ~]$ file base_user.sql
base_user.sql: UTF-8 Unicode text, with very long lines
[root@www.cnscn.org ~]$ iconv -f utf-8 -t gbk base_user.sql >base_user_gbk.sql
[root@www.cnscn.org ~]$ mysql -uroot
mysql> use testdb;
Server characterset: latin1
Db characterset: gbk
Client characterset: latin1
Conn. characterset: latin1
mysql>set names 'gbk';
mysql> status;
Server characterset: latin1
Db characterset: gbk
Client characterset: gbk
Conn. characterset: gbk
mysql> source base_user_gbk.sql;