mysql備份與恢復
數據備份:
Runtime rt = Runtime.getRuntime();
String run [] = {"cmd","/c",
"c://mysqldump -hlocalhost -uroot -pxxxx --databases cache >e://cache.sql"};
rt.exec(run);
注意點:
這里使用cmd 去直接運行
mysqldump -hlocalhost -uroot -p1234 --databases cache >e://cache.sql
文件正常但是如果使用exec(run) 會發現文件是空的,這個網上查了一些博客。說是因為路徑中文件夾帶有空格導致的問題。
直接把mysql/bin 下面的文件mysqldump拷貝到沒有空格的路徑下面
執行-》正常
數據還原:
Runtime rt = Runtime.getRuntime();
String run [] = {"cmd","/c",
"c://mysql -hlocalhost -uroot -pxxxx cache <e://cache.sql"};
rt.exec(run);
執行程序如果出現失敗或者失效但是cmd正常 那么問題也是如上。

浙公網安備 33010602011771號