jsp mysql备份_mysql – 来自jsp页面的数据库备份

如果您使用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应该存在,或者您可以提供您选择的任何其他路径.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值