import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MysqlUtil {
private static String mysqlIp = "127.0.0.1";
private static String mysqlPort = "3306";
private static String userName = "root";
private static String password = "123456";
private static String database = "vueblog";
private static String filePath = "D:\\oldDatabase";
private static final SimpleDateFormat yearMonthDayFormat = new SimpleDateFormat("yyyy-MM-dd");
public static void statisticTasks() {
String format = yearMonthDayFormat.format(new Date());
if (!new File(filePath).exists()) {
new File(filePath).mkdir();
}
String resultFile = filePath + File.separator + mysqlIp + "_" + database + "_" + format + ".sql";
new File(resultFile).delete();
try {
String cmd = "mysqldump -h" + mysqlIp + " -P" + mysqlPort + " -u" + userName + " -p" + password + " --databases " + database + " > " + resultFile;
System.out.println(cmd);
Process process = Runtime.getRuntime().exec("cmd /c " + cmd);
if (process == null) {
System.err.println(process.getErrorStream());
process.getErrorStream();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
statisticTasks();
}
}