I have a MySQL database for which I wish to dump schemas for views. How do I do this? I tried mysqldump with --no-data, but that only dumps table schemas.
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` */;
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:
Use --opt option while making the dump:
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
The other answers did not but this worked for me...