1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DBの移行でハマる

Posted at

やったこと

社内システムのDBをmysqldumpで定期的にダンプしている。このダンプは、ユーザーDBを含めた全てのDBをダンプしている。
それを使って検証用VMを立ち上げたいと思ったのがきっかけ。やったことは

  • DBのダンプをSCPで転送
  • mysql -u root -p < dump.sqlでそのまま書き込み

この2点。

この後、PHPのWebアプリをDocumentRootに転送した後、アクセスしてみると

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user

その後色々してみたけど、ユーザーでログインもできない状態。なにこれ怖い。

原因の推測と対応

まあどう考えても、横着して全部のDBを一気にインポートしたのが間違いだと思う。

そういうわけで、ひとまずユーザーを全て削除してみることに。

select Host, User, Password from mysql.user;でユーザーを取得して、root以外は全て消す。

その後、もともと設定していたユーザーを登録し直す

結果

直った!MySQLに勝った!

MySQLのユーザーを移行する場合は、userテーブルだけdumpして、SQL見ながら実行するのが一番堅実だと思います。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?