mysql的中文乱码,大多是因为mysql的编码选择造成的。
以mysql的两个相同结构的表间进行数据迁移为例,做了三种情况的测试,并提出解决乱码的解决方法如下:
Migration between MySQLs
1)
Migration between character set : utf8
Amend my.ini (2 positions)
default-character-set=latin1
=>
default-character-set=utf8
2)
Migration between character set : origin is utf8 ==>
the
destination is latin1
Alter destination:
-
alter database [db_name] default character set utf8;
-
alter table [table_name] default character set
utf8;
- alter table [table_name] change [field_name]
[field_name] [filed type] varchar(45) character set utf8;
users(id, user_name)
alter table users change user_name user_name varchar(45)
character set utf8;
3)
Migration between character set : origin is
latin1 ==>
the destination is utf8
If the origin is latin1, cannot
insert Chinese Character.