Phpmyadmin export VIEW without DATABASE_NAME or ALGORITHM

后端 未结 7 1909
忘了有多久
忘了有多久 2021-02-03 11:29

When exporting a sql dump with phpmyadmin it creates the VIEW table like this:

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER 
VIEW `         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-03 12:01

    To remove database names from the result, you should set default database name, e.g. -

    USE db_name;
    SHOW CREATE VIEW view_name;
    

    You will get something like this (DDL without database names) -

    CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY DEFINER VIEW `view1`
    AS SELECT `table1`.`column1` AS `column1` FROM `table1`
    

    The definer is a view property, I have not seen any options that could remove this property from the SHOW CREATE VIEW result. So, you will need to parse the text and modify it manually.


    Also, you can try 'Generate Schema Script' or 'Backup' tool with 'Exclude DEFINER and SQL SECURITY clauses' option in dbForge Studio for MySQL. It will help you to generate the script you want in a few steps:

    • select view in the Database Explorer
    • open popup-menu and click on 'Generate Schema Script...' command
    • find option 'Exclude DEFINER and SQL SECURITY clauses' and check it
    • press 'Generate' button to build and open SQL text.

提交回复
热议问题