How do I dump view schemas for a MySQL database?
Solution 1:
I think you might either be passing some other options to mysqldump, or using a version of mysqldump that doesn't understand views (perhaps it's too old). When I run mysqldump --no-data, it does dump out the view definitions. See the below:
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `t` AS select 1 AS `1` */;
Solution 2:
Use --opt option while making the dump:
mysqldump -hserver -uUser -ppasswd -no-data --opt export > export.sql
Solution 3:
Mysqldump won't have any options to dump only on views.The below command will help you to take the backup of only views.
mysql -uroot -pPassword INFORMATION_SCHEMA --skip-column-names -e "select table_name from tables where table_type = 'VIEW' and table_schema = 'sakila'" | xargs mysqldump -u root -pPassword sakila > only_views.sql