使用Java远程备份MySQL数据库 [英] Use Java to remotely backup a MySQL database

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

问题描述

我正在尝试创建通过 Java 远程备份 MySQL 数据库的软件.我无权访问任何控制台,但我可以运行 MySQL 命令和语句.我需要将数据库备份到.sql"文件中,然后可以使用这些文件进行恢复.

I trying to create software which will backup MySQL databases remotely via Java. I do not have access to any console, but I am able to run MySQL commands and statements. I need to backup the databases into ".sql" files which can then be used to restore.

如何在没有控制台的情况下备份 MySQL?是否可以进行 sqldump?

How can I go about backing up MySQL without the console? Is it possible to do a sqldump?

我目前的想法是对每个表执行以下过程:

My current thought is to do the following procedure for each table:

  1. 使用 SHOW TABLES 列出要备份的表
  2. 获取表名
  3. 使用SHOW COLUMNS FROM tablename;
  4. 获取表模式
  5. 计算总行数
  6. 以 1000 行为增量从表中选择所有内容(以跟踪下载百分比)
  7. 在执行此操作时,打开一个 FileOutputStream 来写入数据被接收到一个文件中.如果存在,它也会放置放置,使用模式创建、锁定和插入,如.sql"中所示文件.

有没有更好的方法来做到这一点,或者我的方法最适合我的情况?我的方法行得通吗?

Is there a better way to do this, or is my method the best for my situation? Will my method work?

推荐答案

您可以使用 JDBC 在数据库中触发普通 SQL 命令,就像使用 mysql 命令行界面时一样.这样你就可以完全控制转储的每个步骤,例如在获取 1000s 增量时显示进度,写入并发日志或报告等.

You could use JDBC to fire plain SQL commands at the database just like you would when using the mysql command line interface. That way you have full control of each step of the dump, e.g. show the progress when fetching 1000s increments, write a concurrent log or report etc.

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

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