LoginSignup
0
0

More than 1 year has passed since last update.

phpMyAdminでバックアップしたzipファイルで復元に失敗したときの対処法

Posted at

DBでのバックアップはphpMyAdminを使っています。
保存形式はzipを使っています。

ある時、バックアップしたzipファイルを使ってインポートしようとしたら、エラーが出てできませんでした。。。
いろいろやってみて解決法が見つかったので、備忘録としてメモします。

起こっている問題

レコード内容を書き換える作業が発生し他ので、作業前にphpMyAdminを使ってバックアップを作成した。
作業に失敗したので、復元しようと考える。
既存のテーブルは一度全て削除。その後、バックアップしておいたzipファイルをインポートすると、以下のエラーが発生した。

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PK' at line 1

エラーがでDBを復元できない。
全てのテーブルを削除してしまっているので、困った。。。

解決方法

いろいろ悪戦苦闘したが、エラーメッセージでググったら以下のサイトを見つけた

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PK' at line 1

これによると、problem solved, it was an issue with the zip file, after unpacking the zip import was successful.とあるので、zip→gzipに変更してみた。

$ unzip backup.sql.zip
$ gzip -c backup.sql > backup.sql.gz

gzip化したバックアップファイルを使い、再度インポートしてみたところ、エラーは発生せずにインポート完了!!

最後に

解決できなくて、一晩悩み続けたけど、寝てからやってみたらすんなりできた。
やっぱりうまくいかない時には眠ってみるっていうのは有効な問題解決の手段なんだと再認識した。

0
0
0

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
0