MySQL backup and restore from command line

a 夏天 提交于 2019-11-29 10:34:45

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/823841/mysql-backup-and-restore-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!