gpt4 book ai didi

mysql - 从jsp页面备份数据库

转载 作者:可可西里 更新时间:2023-11-01 07:54:15 25 4
gpt4 key购买 nike

我有一个带有 MySQL 数据库的 struts 2 (jsp) 网络应用程序

是否可以从jsp/java页面备份数据库

是否可以用同样的方式恢复

请给我一些教程或提示..

我的实际需要是授予管理员访问权限,以使用 gui 本身进行备份和恢复,而无需从服务器访问 MySQL

提前致谢..

最佳答案

如果你使用的是 mySQl,你可以做类似的事情

   static int BUFFER = 10485760;      

public static String getData(String host, String port, String user, String password, String db) throws Exception {

Process run = Runtime.getRuntime().exec(
"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump --host=" + host + " --port=" + port +
" --user=" + user + " --password=" + password +
" --compact --databases --add-drop-table --complete-insert --extended-insert " +
"--skip-comments --skip-triggers "+ db);
InputStream in = run.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer temp = new StringBuffer();
int count;
char[] cbuf = new char[BUFFER];

while ((count = br.read(cbuf, 0, BUFFER)) != -1)
temp.append(cbuf, 0, count);

br.close();
in.close();

return temp.toString();
}

public static void main(String[] args) {
byte[] data = BackupRestore.getData("localhost", "3306",
"root", "", "test").getBytes();
File filedst = new File(path);
FileOutputStream dest = new FileOutputStream(filedst);
dest.write(data);
}

但我相信,除非您没有任何令人信服/奇特的理由来使用这种更好的用户命令行工具

您可以使用 MySQL 附带的 GUI 工具,经过更多测试且更易于使用。

String path="C:/datadump/db_backup.sql"

确保路径 C:/datadump 应该存在,或者您可以提供您选择的任何其他路径。

关于mysql - 从jsp页面备份数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8238095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com