简体   繁体   English

如何使用NetBeans备份和还原MySQL数据库?

[英]How to Backup and Restore a MySQL Database using NetBeans?

I'm developing a software with NetBeans and I'm using MySQL as my Database server. 我正在使用NetBeans开发软件,并且正在使用MySQL作为数据库服务器。 I' planning to use two buttons as, "Backup Database" and "Restore Database" to respective functions. 我打算使用两个按钮分别作为“备份数据库”和“还原数据库”。 How to accomplish these functions? 如何完成这些功能? And for both functions, it would be awesome if File Chooser window is used for the functions too. 对于这两个功能,如果也将“文件选择器”窗口也用于这些功能,那就太棒了。 Thanks in advance! 提前致谢! :) :)

What about creating a dump and saving it? 创建转储并将其保存怎么办? and then running it when you want to restore? 然后在要还原时运行它?

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

EDIT: 编辑:

Well since you say you dont really know how to achieve this then ill be more specific. 好吧,既然你说你真的不知道如何实现这一目标,那么就更具体一些。

mysqldumpl must be run from a commandline for this pls read this link: mysqldumpl必须从命令行运行,为此请阅读以下链接:

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

your code should look something like this: 您的代码应如下所示:

String yourCommand = "mysqldump -h localhost -u [user] -p[database password] -c --add-drop-table --add-locks --all --quick --lock-tables [name of the database] > sqldump.sql";
Runtime.getRuntime().exec(yourCommand);

After that you should have succefully saved a file with all the data of your database 之后,您应该成功保存了包含数据库所有数据的文件

the last part of the string "sqldump.sql" is the name of the file, you can set your own name with file chooser, and replace that name with the one from the user, google will help you with that. 字符串"sqldump.sql"的最后一部分是文件的名称,您可以使用文件选择器设置自己的名称,然后用用户的名称替换该名称,google会为您提供帮助。

Well first get that done Post your code when you have it running and then we can tackle the restoring of the DB 好吧,先完成它,然后在运行时发布代码,然后我们就可以解决数据库的还原问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM