Java 导出MySQL数据库
核心命令
mysqldump -uusername -ppassword -hhost -Pport exportDatabaseName > exportPath
Java 执行Shell
Runtime.getRuntime().exec(commands);
直接执行上述命令, 无法解析重定向符号 >,所以使用以下方式
String[] commands = {"/bin/sh", "-c", "mysqldump -uroot -p123456 -hlocalhost -P3306 dbName > ~/db.sql}
Runtime.getRuntime().exec(commands);