24
25

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.

MySQLのViewのDefinerを変更する

Last updated at Posted at 2015-02-18

mysqldumpを実行したところ以下のようなエラーが発生

$ mysqldump -uhogeuser -p some_db > /tmp/some_db.dmp
                                                                        
Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1449: The user specified as a definer ('fugauser'@'%') does not exist when using LOCK TABLES

DBを移行したときに、some_dbに含まれるviewを作成したときのユーザを削除したか、Import時に別のユーザで実行してしまったのが原因。

viewの定義をみると

CREATE ALGORITHM=UNDEFINED DEFINER=`fugauser`@`%` SQL SECURITY DEFINER VIEW `asdf` AS SELECT....

となっていた。
DEFINERとはViewの定義者で、参照権限を設定できるもよう。
対応方法は以下の2通り

  1. 元のDBユーザ(ここではfugauser)を作成する
  2. Viewの定義SQLを書き換えてDEFINERを変更(ここではfugauser->hogeuser)する。
  3. DEFINERのデフォルトはCURRENT_USERになるので、VIEWのDEFINER=CURRENT_USERとしてよいなら、一旦VIEWをDROPしてしまって、再度Viewを作成

2の方法は以下の通り

変更前:CREATE ALGORITHM=UNDEFINED DEFINER=`fugauser`@`%` SQL SECURITY DEFINER VIEW `asdf` AS SELECT....

変更後:ALTER ALGORITHM=UNDEFINED DEFINER=`hogeuser`@`%` SQL SECURITY DEFINER VIEW `asdf` AS SELECT....
24
25
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
24
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?