Can MySQL reliably restore backups that contain views or not?

后端 未结 4 984
情书的邮戳
情书的邮戳 2021-02-04 14:15

Environment: Ubuntu 11.10, MySQL 5.1.58

I have a small database with views. When I try to dump and restore, I get

ERROR 1356 (HY000) at line 1693: View          


        
4条回答
  •  悲&欢浪女
    2021-02-04 15:07

    What I found to solve the problem is to use the 'sql security invoker' when creating the view initially.

      create or replace sql security invoker view  as select ...
    

    It defines access to the view by the invoker, and not the definer.

    Then when the dump file is loaded, the view is create correctly.

    With Amazon RDS:

    To make this work with Amazon RDS, which does not allow super priv (which is needed to do the above) one can run this command to on the dump file:

     # Remove DEFINER statement from VIEWS in Dump file
     sed -i 's/\sDEFINER=`[^`]*`@`[^`]*`//' $DUMPFILE_NAME
    

    Then when the dump file is loaded into an RDS, the view is create correctly.

提交回复
热议问题