cuiyi's blog(崔毅 crazycy)

记录点滴 鉴往事之得失 以资于发展
数据加载中……

mysql乱码编码的解决之道(不含分析)

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;
    • example

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.

 


posted on 2007-12-23 18:07 crazycy 阅读(427) 评论(0)  编辑  收藏 所属分类: DBMS


只有注册用户登录后才能发表评论。


网站导航: