有效告別數據庫亂碼, gbk/gb2312/big5/latin1轉utf-8
1. 在shell中用root登陸服務器
2. 進入mysql目錄 (linux Server):
- cd /var/lib/mysql/
- mysqldump –user=username –password=password –default-character-set=latin1 –skip-set-charset dbname > dump.sql
4. 把數據庫數據從latin1轉換成utf-8編集:
- sed -r ’s/latin1/utf8/g’ dump.sql > dump_utf.sql
5. 創建新的urf-8新數據庫:
- mysql –user=username –password=password –execute=”DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;”
6. 以正確編集導入轉碼後的數據庫數據:
- mysql –user=username –password=password –default-character-set=utf8 dbname