数据从mysql4.1.x倒到mysql5.0.x后中文乱码的问题

今天
把个系统从一台机器上挪到另外一台机器
由于牵涉到数据库升级
(原来的是4.1.x,中文数据编码是gbk;新的是5.0.x,中文数据编码想用utf-8)
所以就比较留心
首先把数据dump出来
mysqldump db1>db1.sql
然后传到新的服务器上
scp db1.sql xxx.xxx.xxx.xxx:/tmp/
再在新的机器上做编码转换
iconv -f gbk -t utf-8 db1.sql>db1utf8.sql
再倒入新的库
mysql db1 然后发现web页面显示需要选gbk才不乱码(跟在老机器上一样)
最后在老机器上dump时加参数指定缺省character-set
mysqldump --default-charcter-set=latin1 db1>db11.sql
这样做的数据拷到新机器上后

iconv -f gbk -t utf-8 db11.sql>db11utf8.sql
再倒入
就没有问题了(库里存的是utf8的数据了)

Discussion Area - Leave a Comment




*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word