如何使用NetBeans备份和还原MySQL数据库? [英] How to Backup and Restore a MySQL Database using NetBeans?

查看:140
本文介绍了如何使用NetBeans备份和还原MySQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NetBeans开发软件,并且正在使用MySQL作为数据库服务器.我打算使用两个按钮分别作为备份数据库"和还原数据库".如何完成这些功能?对于这两个功能,如果也将文件选择器"窗口也用于这些功能,那就太棒了.提前致谢! :)

I'm developing a software with NetBeans and I'm using MySQL as my Database server. 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

好吧,因为您说过您真的不知道如何实现这一目标,所以请更加具体.

Well since you say you dont really know how to achieve this then ill be more specific.

mysqldumpl必须从命令行运行,为此请阅读以下链接:

mysqldumpl must be run from a commandline for this pls read this link:

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

您的代码应如下所示:

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

字符串"sqldump.sql"的最后一部分是文件的名称,您可以使用文件选择器设置自己的名称,然后用用户的名称替换该名称,Google会为您提供帮助.

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.

首先要完成 在运行代码后将其发布,然后我们可以解决数据库的还原

Well first get that done Post your code when you have it running and then we can tackle the restoring of the DB

这篇关于如何使用NetBeans备份和还原MySQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆