MySQL文字コードの移行

Latin1からUTF-8に移行します。

環境

  • FreeBSD 6.1
  • MySQL 5.0.45

手順

  1. MySQLをリビルド
    • vi /usr/local/etc/pkgtools.conf
      • MAKE_ARGSに次のコードを追加
      • 'mysql-*' => 'WITH_CHARSET=utf8 WITH_XCHARSET=all WITH_COLLATION=utf8_general_ci'
    • portupgrade -f mysql-*
  2. nkfをインストール
    • portinstall ja-nkf
  3. データベースのバックアップ
    • /usr/local/etc/rc.d/mysql-server stop
    • cd /var/db && cp -Rp mysql mysql.20070929
    • /usr/local/etc/rc.d/mysql-server start
  4. ダンプ
    • mysqldump -u root -–default-character-set=latin1 -c -n -d wordpress > ~/wordpress_latin_scheme.sql
    • mysqldump -u root -–default-character-set=latin1 -c -n -t wordpress > ~/wordpress_latin_data.sql
  5. 文字コード変換
    • nkf -wE wordpress_latin1_data.sql > wordpress_w_data.sql
    • sed 's/CHARSET=latin1/CHARSET=utf8/g' wordpress_latin1_scheme.sql > wordpress_utf8_scheme.sql
    • nkfは場合によっては自動変換にまかせたほうがよい。wordpress_w_data.sql がutf8となっていることを確認すること
      nkf -w wordpress_latin1_data.sql > wordpress_w_data.sql
  6. データベースの再作成
    • mysql -u root
      • drop database wordpress;
      • create database wordpress default character set utf8;

参考

WordPressのテーブルを削除したいときには下記を参考にしてください。

drop table wp_categories        ;
drop table wp_comments          ; 
drop table wp_linkcategories    ; 
drop table wp_links             ; 
drop table wp_options           ; 
drop table wp_post2cat          ; 
drop table wp_postmeta          ; 
drop table wp_posts             ; 
drop table wp_usermeta          ; 
drop table wp_users             ;

The income from AdSense serves as an activity fund of SSS(G).

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2009-03-06 (金) 16:51:07 (545d)