LoginSignup
0

More than 3 years have passed since last update.

MySQLのDBからAWSのRDSへデータをインポートする(LightSailからAWS編)

Last updated at Posted at 2020-07-18

Amazon LightsailからAWS RDSに移行しようと思ったが、上記記事を参照すると思いの他面倒そうだった。
素直にエクスポート、インポートするとなるほど、下記のエラーでインポート出来ない。

ERROR 1227 (42000) at line 18: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation

これはAmazon RDSの問題なのでLightsail以外のどんなMysqlからインポートしようとしても同様のエラーが出ると思う。
上記記事では色々な手法でエラーを回避しているが、よくよく読んだらmysqldumpを実行時に下記のようなワーニングが出ていた。

Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.

ん?これは素直にこのオプションを付けてエクスポートすれば良いのでは無いだろうか。
というわけで実践。

旧DBからエクスポート
mysqldump dbname -u username -h hostname --routines=0 --triggers=0 --events=0 --set-gtid-purged=OFF -p > dbname.sql

新DBへインポート
mysql -u new_username -p -h new_hostname new_dbname < dbname.sql

無事にインポート出来ました。

※オプションを付ける事で何が起こるのか理解してません。
※新DBでは予め空のデータベースを作成しておく必要はあります。
※記事冒頭に記載したリンクを参照して作業を始めたので、log_bin_trust_function_creators の値を1に変更しているが、恐らくこの作業はしなくてもインポート出来ると思います。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0