7

I am using Command line to backup and restore MYSQL Database. Let use I m having a Database Data1 having Views and Procedures in it. When in Cmd line, I use mysqldump i.e

..>bin> mysqldump -u root -proot Data1 > Datafile.mysql

When I use above Cmd, It creates a Backup file on bin Folder of Mysql with Dtafile.mysql Name.

but the thing is it creates Back Up of Only Tables, Not Procedures.

And when I m restoring it in a Blank Database "Data2"

..bin> mysql - u root -proot Data2 < Dataafile.mysql

What it does is, It creates all the Tables and Convert Views into Tables and No Procedures has been restored.

Means I am not able to Restore my full database backup with All tables, views and Procedures.

Can any of you guys help it.. I would be extremely Thankfull.

2 Answers 2

12

Include the "--routines" parameter for mysqldump and it will dump the procedures.

EDIT #1 : Your mysqldump command should now look like,

mysqldump -u root -proot --routines Data1 > Datafile.mysql

EDIT #2:
You need to add the --add-drop-table switch as well if you want to preserve your Views. The reason is Views are created in two steps (first as dummy tables, then as real views). Also please take a note that Tables and Views share the same name space, so don't get misled by the output given by "Show Tables" command in the mysqlclient. Use "Show Create View vw_test" instead if that command shows you the create view query then bingo, also to make sure that the views have been restored correctly insert some data into the relevant tables in your other database and then run a select query on the view, if the data ties up than you hit a bulls eye, pat yourself on the back :) else you can always return to this wonderful community at Stackoverflow.

So (to maintain views) your mysqldump command should now look like this

mysqldump -u root -proot --routines --add-drop-table Data1 > Datafile.mysql

HTH

12
  • 1
    Hey how do I include --routines while taking dump?? CAn you plz explain a bit May 5, 2009 at 8:40
  • Hi, I have edited my answer above to show the command to use.
    – Anand Shah
    May 5, 2009 at 9:09
  • Hi Thanks.. It Works.. One More Problem, I am facing Is that in "Data1" I am having Views that refers other databases. when I am restoring it, It convert all Views into tables. i.e I m having View vw_test in Data1 but when I restore it, It becomes a table with Name vw_test. What would be the problem. Help me. Thanks a Lot. May 5, 2009 at 9:28
  • Hi Thanks for your reply, but .. It doesn't work. Still the script convert Views(Having Reference to other database) into Tables. May 5, 2009 at 10:25
  • Show Create Table shows the Table structure of vw_test. Create Table vw_test(id int...) in this manner. May 5, 2009 at 10:48
-1

there is three best ways to backup database use command line,phpmyadmin or mysql administrator mysql database backup and restore in easy way, use mysql database backup

mysql administrator

phpmyadmin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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