Java达到MySQL数据库备份(两)

        博客《Java实现MySQL数据库备份(一)》使用I/O流的方式实现了MySQL数据库的备份,这样的方法比較繁杂。以下介绍还有一种备份MySQL数据库的方法:

import java.io.File;
import java.io.IOException;/*** MySQL数据库备份* * @author GaoHuanjie*/
public class MySQLDatabaseBackup {/*** Java代码实现MySQL数据库导出* * @author GaoHuanjie* @param hostIP MySQL数据库所在server地址IP* @param userName 进入数据库所须要的username* @param password 进入数据库所须要的密码* @param savePath 数据库导出文件保存路径* @param fileName 数据库导出文件文件名称* @param databaseName 要导出的数据库名* @return 返回true表示导出成功,否则返回false。*/public static boolean exportDatabaseTool(String hostIP, String userName, String password, String savePath, String fileName,	String databaseName) {File saveFile = new File(savePath);if (!saveFile.exists()) {// 假设文件夹不存在saveFile.mkdirs();// 创建文件夹}if (!savePath.endsWith(File.separator)) {savePath = savePath + File.separator;}StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("mysqldump").append(" --opt").append(" -h").append(hostIP);stringBuilder.append(" --user=").append(userName) .append(" --password=").append(password).append(" --lock-all-tables=true");stringBuilder.append(" --result-file=").append(savePath + fileName).append(" --default-character-set=utf8 ").append(databaseName);try {Process process = Runtime.getRuntime().exec(stringBuilder.toString());if (process.waitFor() == 0) {// 0 表示线程正常终止。return true;}} catch (IOException e) {e.printStackTrace();} catch (InterruptedException e) {e.printStackTrace();}return false;}public static void main(String[] args) throws InterruptedException {if (exportDatabaseTool("172.16.0.127", "root", "123456", "D:/backupDatabase", "2014-10-14.sql", "test")) {System.out.println("数据库备份成功。!!");} else {System.out.println("数据库备份失败!!!");}}
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

转载于:https://www.cnblogs.com/zfyouxi/p/4834663.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/419537.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

找不到android的sdk,CircleCI – 找不到Android Studio项目的SDK位置

尝试在CircleCI上构建项目时,在gradle构建期间发生以下错误.这个问题的原因是什么?我正在运行CircleCI 2.0.FAILURE: Build failed with an exception.What went wrong: A problem occurred configuring project ‘:app’.SDK location not found. Define location …

选项卡,下拉菜单操做时的页面数据更新,highcharts,d3 结合。

1.选项卡:给要选中的元素添加css样式,加active,单击时先移除active,再把当前单击元素添加active。 单击时页面切换,按钮和页面要有关联,通过获取$(this).text();年龄,教育,职业&…

oracle之数据处理之约束练习

57. 定义非空约束1). 非空约束只能定义在列级.2). 不指定约束名create table emp2 (name varchar2(30) not null, age number(3));3). 指定约束名 create table emp3(name varchar2(30) constraint name_not_null not null, age number(3));58. 唯一约束1). 列级定义①. 不指定…

小米9android系统怎么关闭,小米MIUI系统怎么禁用虚拟键 小米MIUI系统禁用虚拟键方法...

想新很多米粉对对miui系统不会陌生。这个系统还很是不错。但是刚刚入手小米手机的米粉可能就不太熟悉了。那么,虚拟键要怎么去禁用呢?下面就一起来看看小米MIUI系统虚拟键禁用方法。大家用安卓手机的时候是否曾遇到过以下折磨人的场景:小米MI…

C#性能优化:延迟初始化LazyT

1. 概述 我们创建某一个对象需要很大的消耗,而这个对象在运行过程中又不一定用到,为了避免每次运行都创建该对象,这时候延迟初始化(也叫延迟实例化)就出场了。 延迟初始化出现于.NET 4.0,主要用于提高性能&…

android手机值不值得买,安卓直屏Redmi K40手机值得买吗?

描述还记得我们上一次谈论直屏与曲面屏的关系吗?小Z从后台留言中发现了很多人确实对如今清一色的旗舰曲面屏感到不满,用着远没有几年前的直屏来得顺手。但在如今的手机市场中,想要找到一款屏幕素质不错,硬件配置足够旗舰&#xff…

oracle之数据处理之视图

--创建视图 create view empview as select employee_id,last_name,salary from employees where department_id80;--查询视图 select * from empview--修改视图 update empview set salary20000 where employee_id179 运行结果 --修改视图 create or replace view empview2 a…

simplified build configuration

http://blogs.msdn.com/b/saraford/archive/2005/08/16/452411.aspx Did you know… That you can hide the solution and advanced build configurations Under Tools – Options – Projects and Solutions – General, there are options for both Always show solution and…

oracle之数据处理之视图练习

62. 查询员工表中 salary 前 10 的员工信息.select last_name, salary from (select last_name, salary from employees order by salary desc) where rownum < 10说明: rownum "伪列" ---- 数据表本身并没有这样的列, 是 oracle 数据库为每个数据表 "加上的…

android集合优化,android-性能优化之集合类优化

优化包括&#xff1a;I/O的优化、网络操作的优化、内存的优化、数据结构的优化、代码层次的优化、UI渲染优化、CPU资源使用率的优化、异常处理的优化等》ArrayList和VectorArrayList和Vector都是内部以数组实现的List&#xff0c;它们两唯一的区别就是对多线程的支持&#xff0…

oracle之数据处理之其他数据库对象

--创建序列 create sequence empseq increment by 10---每次增长10 start with 10--从10开始 maxvalue 100--提供最大值 cycle --循环 nocache --不需要缓存登录 运行结果 --查看 查看 select empseq.nextval from dual 运行结果 --创建表 create table emp11 as select empl…

android 线程太多,应用程序可能在其主线程上做了太多的工作。

任何开始开发android应用程序的人都会在logcat上看到这个消息。编舞(ABC)&#xff1a;跳过xx帧&#xff01;应用程序可能在其主线程上做了太多的工作。“那么&#xff0c;它到底意味着什么&#xff0c;你为什么要关心它&#xff0c;以及如何解决它。这意味着您的代码需要很长时…

关于Docker官方CentOS镜像无法启动mysqld的总结

很多童鞋反映&#xff0c;在Docker官方CentOS镜像中安装了Mysql server后&#xff0c;无法正常启动。 无法正常启动表现为两种情况&#xff1a; 1> 初始完数据库后&#xff0c;mysqld启动报错 2> systemctl start mysqld或者service mysqld start报错 首先重现一下现场。…

oracle之数据处理之其他数据库对象练习

1. 创建序列dept_id_seq&#xff0c;开始值为200&#xff0c;每次增长10&#xff0c;最大值为10000 a) create sequence dept_id_seq b) start with 200 c) increment by 10 d) maxvalue 10000 2. 使用序列向表dept中插入数据 a) insert into dept01 b) values(dept_id_seq.nex…

android 刷rom,刷ROM是什么?刷ROM是什么意思?

刷ROM是什么意思首先&#xff0c;ROM是由英文Read only Memory的首字母构成的&#xff0c;意为只读存储器。顾名思义&#xff0c;就是这样的存储器只能读&#xff0c;不能像RAM一样可以随时读和写。它只允许在生产出来之后有一次写的机会&#xff0c;数据一旦写入则不可更改。它…

网站

Json解析&#xff1a;http://json.tongxiehui.net/ MD5破解&#xff1a;http://www.cmd5.com/转载于:https://www.cnblogs.com/Eazy/p/4840789.html

oracle之set运算符和练习

--创建表 create table emp01 as select * from employees where department_id in (70,80)-- --创建表 create table emp02 as select * from employees where department_id in (80,90) --查询 --并集 select * from employees where department_id in (70,80) union all se…

html自动加https,http自动跳转https的配置方法

IIs中实现Http自动转换到Https方法介绍 (403跳转对SEO有一定影响)1.下载安装URL重写模块&#xff1a;Microsoft URL Rewrite Module32位&#xff1a;http://download.microsoft.com/download/4/9/C/49CD28DB-4AA6-4A51-9437-AA001221F606/rewrite_x86_zh-CN.msi64位&#xff1a…

活动页面html设计,活动查看页面.html

&#xfeff;活动查看页面$axure.utils.getTransparentGifPath function() { return resources/images/transparent.gif; };$axure.utils.getOtherPath function() { return resources/Other.html; };$axure.utils.getReloadPath function() { return resources/reload.html…