[WordPress General] MySQLコマンドラインでDBバックアップ
引っ越しやバックアップなど、phpMyAdminなしでインポート・エクスポートする方法。
[markdown]
> * [データベースのバックアップ – WordPress Codex 日本語版](http://wpdocs.sourceforge.jp/%E3%83%87%E3%83%BC%E3%82%BF%E3%83%99%E3%83%BC%E3%82%B9%E3%81%AE%E3%83%90%E3%83%83%E3%82%AF%E3%82%A2%E3%83%83%E3%83%97)
## WordPressのテーブル名を確認する
“`
$ mysql -u
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
# 省略
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| wp_blog |
+——————–+
2 rows in set (0.00 sec)
mysql> exit
“`
wp_ではじめている方が多いかもしれません。
## データベースのバックアップ
“`
mysqldump –add-drop-table -h
“`
## バックアップをコピー(SCP)する
新しいサーバにログインして、バックアップファイルを SCP でコピーしてきます。
“`
% scp <古いサーバのユーザー名>@oldserver.jp:~/blog.bak.sql.bz2 ./
blog.bak.sql.bz2 100% 590KB 590.4KB/s 00:00
“`
## バックアップファイルからの復元
バックアップファイルを展開します。
“`
% bzip2 -d blog.bak.sql.bz2
“`
インポートをするデータベースを作成します。
“`
% mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
# 省略
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> create database wp_blog;
Query OK, 1 row affected (0.00 sec)
mysql> exit
“`
インポートします。
“`
% mysql -h
“`
新しいサーバで復元する。
“`
% cd public_html
% scp <古いサーバのユーザー名>@oldserver.jp:~/html.tar.gz ./
% tar xvfzp html.tar.gz
“`
* 新しいサーバのwp-config.phpを書き換え
* 起動確認
* DNS設定を切り替え
[/markdown]