且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-11-02 22:00:00

如何创建转储并保存转储?然后在要还原时运行它?

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