最近在 windows 上匯出/匯入資料庫時遇到 UTF-8 編碼問題,奇怪之前在 linux 上執行從未遇到的說,原來 default-character-set 是 latin1,所以在匯出/匯入時要指定成 UTF-8 就沒問題了。
匯出資料庫
- PATH=C:\wamp\bin\mysql\mysql5.5.8\bin
-
- REM export 'dbname' database
- mysqldump -uroot -p1234 --default-character-set=utf8 dbname > dbname.sql
-
- REM other dbname ...
- pause
PATH=C:\wamp\bin\mysql\mysql5.5.8\bin
REM export 'dbname' database
mysqldump -uroot -p1234 --default-character-set=utf8 dbname > dbname.sql
REM other dbname ...
pause
匯入資料庫
- PATH=C:\wamp\bin\mysql\mysql5.5.8\bin
-
- REM import 'dbname' database
- mysql -uroot -p1234 -e "DROP DATABASE IF EXISTS `dbname`;"
- mysql -uroot -p1234 -e "CREATE DATABASE `dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
- mysql -uroot -p1234 --default-character-set=utf8 dbname < dbname.sql
-
- REM other dbname ...
- pause
PATH=C:\wamp\bin\mysql\mysql5.5.8\bin
REM import 'dbname' database
mysql -uroot -p1234 -e "DROP DATABASE IF EXISTS `dbname`;"
mysql -uroot -p1234 -e "CREATE DATABASE `dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
mysql -uroot -p1234 --default-character-set=utf8 dbname < dbname.sql
REM other dbname ...
pause
0 回應:
張貼留言