MySQL encoding and converting databases to UTF8

1.) Dump the DB:
mysqldump –user=username –password=password –default-character-set=latin1 –skip-set-charset dbname > dump.sql

2.) Replace all latin1 instances with utf8:
sed -r ’s/latin1/utf8/g’ dump.sql > dump_utf.sql

3.) Delete the old DB, create a new one in UTF8:
mysql –user=username –password=password –execute=”DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;”

4.) Load the dump into the new DB:
mysql –user=username –password=password –default-character-set=utf8 dbname < dump_utf.sql

original link 

发表你的看法

最近主题:

最近评论

  • erick: 搞定了, 从win上转过来的,比较呆, ...
  • erick: 装成功能 了,想用gui工具访问mysql,请...
  • Gary: Did you write this skin for Maxthon? If so, can I...
  • andy: what's iter...
  • g.zhen.ning: 有道理,有点喜欢ruby,不过不知道前...