Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted

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:

/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `t` AS select 1 AS `1` */;
share|improve this answer
maybe the questioner didn't have a look in the mysqldump? To dump the views commented out is a very bad style by MySQL. There should at least a hint in the docs, but there is none. – Thomas Berger Aug 17 '11 at 19:22
Nevermind, I was wrong. It did dump the views. Thank god. Cool. – Chad Johnson Aug 17 '11 at 19:33
These are conditional comments that execute depending on your version of MySQL, see: – Gary Aug 15 '13 at 19:43

Use --opt option while making the dump:

mysqldump -hserver -uUser -ppasswd -no-data --opt export > export.sql
share|improve this answer
Although for security reasons, I'd not put the password on the command line, I'd let the program prompt for it. – mdpc Nov 29 '12 at 20:41

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

share|improve this answer

The other answers did not but this worked for me...

mysqldump --skip-comments --skip-opt --complete-insert --add-drop-table --database dbname -p
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.