データベース移植作業

ユーザーの作成

移動先のデータベースにも同じユーザーを作成しておきました(パスワードも同じにしておく)

データベースのバックアップ

root@xxxxx:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1094
Server version: 8.0.25-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| xxxxxxxx           |
| yyyyyyyy           |
| information_schema |
| mysql              |
| AAAAAAAA           |
| performance_schema |
| sys                |
| webdata            |
+--------------------+
8 rows in set (0.00 sec)

mysql>

バックアップするマシンのmysqlにrootユーザー(mysqlの)でログインし、データベースの一覧を確認する

同様にバックアップ先のマシンのデータベースを確認し、バックアップ先にないものをバックアップします。コマンドは mysqldumpを使用しました。とりあえず移植と言うことで深く考えずにバックアップ先にないものを個別にバックアップしました。

root@xxxxx:~#  mysqldump --lock-all-tables -u root -p --databases xxxxxxxx > xxxxxxxx

全てのデータベースを一度にバックアップする方法もありますが、システム用のデータベースも一緒になってしまい、バックアップ先で競合するのを避けるため、個別としました。

次にバックアップ先のマシンでリストアします。

user@yyyy:~$ mysql -u root -p < xxxxxxxxx

全てのデータベースをリストアして無事終了