我想从我的swing应用程序导出数据库tp进行备份 我正在谷歌上搜索,与我合作的唯一方法就是:
FileWriter fw = null;
String path="C:/Users/mypc/Desktop/tesst/back.sql";
String dumpCommand ="mysqldump -u root --password= gestiondestock > "+path;
// Runtime.getRuntime().exec("mysqldump -u root --password= gestiondestock > "+path);
File data = new File(path);
try{
fw = new FileWriter(data);
fw.close();
}catch(IOException ex){
ex.printStackTrace();
}
Runtime rt = Runtime.getRuntime();
try {
Process proc = rt.exec(dumpCommand);
InputStream in = proc.getInputStream();
InputStreamReader read = new InputStreamReader(in,"latin1");
BufferedReader br = new BufferedReader(read);
BufferedWriter bw = new BufferedWriter(new FileWriter(data,true));
String line=null;
StringBuffer buffer = new StringBuffer();
while ((line=br.readLine())!=null){
buffer.append(line+"\n");
}
String toWrite = buffer.toString();
bw.write(toWrite);
bw.close();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
但我只得到日期基础信息而不是创建表并插入....
我只收到这些信息:
- 主持人:localhost数据库:gestiondestock
- 服务器版本5.1.36-community-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
如何修复并获取sql文件的所有信息??,当我尝试在phpmyadmin上导出时,我获取所有信息
dumpCommand可以从cmd框中手动完成
以及导入它的最佳方法!!
我不能在不运行shell的情况下进行重定向,我上面没有这样做。 所以我必须这样做:
String path="C:/Users/mypc/Desktop/tesst/back.sql";
String dumpCommand = "mysqldump -u root gestiondestock --result-file="+path;
- result-file =“+ path
答案 0 :(得分:0)
mysqldump
命令似乎有问题。而不是这个
mysqldump -u root --password= gestiondestock > path
试试这个,
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
另请参阅此链接
http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/