Phpmyadmin export VIEW without DATABASE_NAME or ALGORITHM

后端 未结 7 1902
忘了有多久
忘了有多久 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:19

    In linux it's very simple to remove unwanted informations in a text file. Given that CREATE VIEW creates something like:

    CREATE ALGORITHM=UNDEFINED DEFINER=USER@HOST SQL SECURITY DEFINER VIEW VIEWNAME ...etc.

    You can use the following sed:

    sed -e 's/ALGORITHM.*DEFINER VIEW/VIEW/' backup-mysqldump.sql > backup.sql
    

    You can also using with mysqldump in a single command, with a pipe:

    mysqldump -uUSERNAME -pPASSWORD database |sed -e 's/ALGORITHM.*DEFINER VIEW/VIEW/' > backup.sql
    

提交回复
热议问题