mysqlのデータベースの移行作業

投稿者: | 2011年9月1日

普段Postgresqlを使っているのでmysqlは勝手が分からずデータベースの移行方法が良く分からなかったが何とか成功したのでメモをしておく。

まず移行側のPCでの準備。
mysqlを使用できる状態にしrootのパスワードを設定する

mysql> SET PASSWORD FOR root@localhost=PASSWORD(‘password’’);
Query OK, 0 rows affected (0.00 sec)

そんで移行もとのデータベースをダンプする。

mysqldump -u root -x –all-databases > mydump.sql

で一気にすべてダンプ使用かと思ったがrootに権限がないとか言われ上手くいかなかったので仕方なく1つ1つダンプすることに。

mysqldump -u joomla -p joomla >joomladb.dump
Enter password:

mysqldump -u xoops -p xoops >xoopsdb.dump
Enter password:

mysqldump -u nucleus -p nucleus >nucleusdb.dump
Enter password:

よく分からないがrootにそれぞれのデータベースに権限を持たせておけば一気にできると思う。
ダンプしたファイルは移行先にftpなどで転送しておく。

いよいよリストアだ。
それぞれのデータベースで同じことをやるだけ。

mysql> create database xoops default character set utf8;
Query OK, 1 row affected (0.02 sec)

mysql> create database joomla default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> create database nucleus default character set utf8;
Query OK, 1 row affected (0.02 sec)

mysql> grant all on xoops.* to xoops@localhost identified by ‘passwowd’;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on joomla.* to joomla@localhost identified by ‘passwowd’;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on nucleus.* to nucleus@localhost identified by ‘passwowd’;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

ここでexit

そしてリストア

# mysql -u xoops -p xoops < xoopsdb.dump
Enter password:
# mysql -u nucleus -p nucleus < nucleusdb.dump
Enter password:
# mysql -u joomla -p joomla < joomladb.dump
Enter password:

なんとか移行できた。

postgresqlの場合はcreatedbはダンプファイル内になるので不要だがmysqlではこれが普通なのかな。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です