java mysql dump_Java 调用Mysql dump 备份数据库详解

news/2025/2/26 19:51:47

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

try {

String name = sdf.format(new Date());

String filePath = System.getProperty("user.dir") + "//" + name + ".sql";

// 系统执行器

Runtime rt = Runtime.getRuntime();

// 导出数据库语句

StringBuffer cmd = new StringBuffer();

cmd.append("mysqldump -u");

cmd.append(ServeConfig.dbUser);

cmd.append(" -p");

cmd.append(ServeConfig.dbPass);

cmd.append(" --set-charset=utf8 ");

cmd.append(ServeConfig.dbName);

// 执行导出获取输入流

Process child = rt.exec(cmd.toString());

InputStream in = child.getInputStream();

InputStreamReader ir = new InputStreamReader(in, "utf8");

// 输出文件

FileOutputStream fo = new FileOutputStream(filePath);

OutputStreamWriter os = new OutputStreamWriter(fo, "utf8");

// 开始读取数据

char[] temp = new char[1024000];

int len = 0;

while ((len = ir.read(temp)) > 0) {

os.write(temp, 0, len);

os.flush();

}

// 别忘记关闭输入输出流

in.close();

ir.close();

os.close();

fo.close();

// 将文件发送到备份服务器

FileUpLoad upload = FileUpLoad.createFileUpLoad(ServeConfig.backAddr, new File(filePath));

upload.tryStart();

upload.waitFinish();

upload.doClose();

} catch (Exception e) {

e.printStackTrace();

}


http://www.niftyadmin.cn/n/3752790.html

相关文章

mysql 商品数据库设计_互联网产品mysql数据库设计总结

mysql数据库性能不比oracle数据库,所以设计上,和oracle有一些不同。下面总结一些互联网产品的数据库设计。1.主键主键可以使用bigint(20) unsigned也可以使用varchar,使用bigint,可以设置为自增主键auto_increment。使用varchar&a…

java多方式登陆_Java 爬虫遇到需要登录的网站,该怎么办?

这是 Java 网络爬虫系列博文的第二篇,在上一篇Java 网络爬虫,就是这么的简单中,我们简单的学习了一下如何利用 Java 进行网络爬虫。在这一篇中我们将简单的聊一聊在网络爬虫时,遇到需要登录的网站,我们该怎么办&#x…

【LeetCode】233. 数字 1 的个数(同剑指Offer43)

一、题目 给定一个整数 n,计算所有小于等于 n 的非负整数中数字 1 出现的个数。 示例: 输入: 13 输出: 6 解释: 数字 1 出现在以下数字中: 1, 10, 11, 12, 13 。二、解决 1、暴力破解 思路: 看完题目,然后可直接写出代码,b…

向文件in.txt中写入字符串helloworld_Python操作文件

1、文件的操作(打开,读,写,重命名,删除等)1.1、打开文件(open)open(文件名,r) : 只读方式打开文件open(文件名,r) : 以读写方式打开,文件不存在报错open(文件名,w) : 可写方式打开文件open(文件名,w) : 以读写方式打开…

nginx安装部署mysql负载均衡_nginx+tomcat+mysql进行负载均衡

Nginxtomcat负载均衡群集准备工作:1台节点部署nginx2台节点部署tomcat1台部署mysql所有机器之间网络互通,并已关闭防火墙和selinux一、Nginx配置1.主配置文件配置:vim nginx.confUpstream字段中配置tomcat所在服务器IP地址,后缀要…

mysql total语法_mysql基础知识语法汇总整理(二)

insert/*insert*/insert into 表名(字段列表) values(值列表);--蠕虫复制 (优点:快速复制数据,测试服务器压力)insert into 表名1_插入 select (字段列表) from表名2_复制;例如:create tablecopy(idint(10) unsigned not null comment id,namechar(20) not null default comme…

mysql中怎么实现Apriori_关联规则Apriori算法及实现(python)

一,概念表1某超市的交易数据库交易号TID顾客购买的商品交易号TID顾客购买的商品T1面包,奶油,牛奶,茶T6面包,茶T2面包,奶油,牛奶T7啤酒,牛奶,茶T3蛋糕,牛奶T8面…

mysql解题思路_BUUCTF-Web-随便注(三种解题思路)

知识点:SQL注入-堆叠注入,sql预处理语句,巧用contact()函数绕过堆叠注入原理:在SQL中,分号(;)是用来表示一条sql语句的结束。试想一下我们在分号(;)结束一个sql语句后继续构造下一条语句,会不会一起执行?因此这个想法也就造就了堆…