Test.java 640 B

123456789101112131415161718192021
  1. /**
  2. * Test$
  3. *
  4. * @author wukai
  5. * @date 2023/11/14 15:13
  6. */
  7. public class Test {
  8. public static void main(String[] args) {
  9. try {
  10. String cmd = " /usr/local/mysql/bin/mysqldump -h192.168.1.28 -P3306 -uroot -p123456 --default-character-set=utf8 doc >/tmp/test.sql";
  11. Process exec = Runtime.getRuntime().exec(cmd);
  12. if (exec.waitFor() == 0) {
  13. System.out.println("数据库备份成功");
  14. } else {
  15. System.out.println("process.waitFor()=" + exec.waitFor());
  16. }
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. }