garbagetown

個人の日記です

MySQL (3)

ボロノートにインストールした MySQL からデータベースを丸ごとエクスポートして、本番機の MySQL にインポートしたいのです。

エクスポート

ローカルの MySQL に接続してデータベースの名称を確認する。

D:\work>mysql -u root -p -b
(snip)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| xxx                |
| mysql              |
+--------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye

mysqldump コマンドに確認したデータベース名を渡してエクスポート。

D:\work>mysqldump xxx > xxx.sql -u root -p
Enter password: ***

D:\work>dir
(snip)
2009/01/25  13:23         1,688,140 xxx.sql

データベース作成

本番機の MySQL にデータベースを作成する。

$ mysql -u root -p
(snip)
mysql> create database xxx;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| xxx                |
| mysql              |
+--------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye

インポート

エクスポートした sql ファイルを FTP か何かで本番機に転送して下記コマンドを実行。

$ mysql xxx < /path/to/xxx.sql -u root -p
Enter password:

MySQL にログインしてインポートしたテーブルやレコード数あたりを確認する。

$ mysql -u root -p
Enter password:
(snip)
mysql> use xxx
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
| Tables_in_xxx     |
+-------------------+
| xxx               |
| yyy               |
| zzz               |
+-------------------+
3 rows in set (0.01 sec)

mysql> select count(*) from xxx;
+----------+
| count(*) |
+----------+
|     4171 |
+----------+
1 row in set (0.00 sec)

お疲れ様でした。