As a junior administrator, I have to back up data every day, and I don't know how to set up automatic tasks, so I basically rely on my hands. This is not only cumbersome, but it also fails to ensure that the A1-influenza virus is isolated, and I have nothing to do with my hands.
So write a java class and load it into the automatic running task of the SPRING program. The idea is to use java to call the system's command symbol and execute the mysqldump command.
·First, under Windows system:
Just a reminder to everyone:
Some people say to use: "mysqldump --uroot --p123456 --opt". But I didn't succeed. Finally, I succeeded using this writing method: "mysqldump --user=root --password=123456 --opt"
It seems to be written in a complete way.
·Then under the Linux system:
The problem that many people encounter here is that the program does not report an error, the command is not executed, and the sql file is not generated. I have started to use the following writing methods: java.lang.Runtime.getRuntime().exec(new String[] { mysql });
java.lang.Runtime.getRuntime().exec(new String[] { "shell "+mysql });
java.lang.Runtime.getRuntime().exec(new String[] { "/bin/bash "+mysql });
java.lang.Runtime.getRuntime().exec(new String[] { "/bin/bash/shell "+mysql });
None of them were successful. Finally, I tried this writing method and it succeeded:
java.lang.Runtime.getRuntime().exec(new String[] { "sh", "-c", mysql });
The premise is that the MySQL bin directory is added to the environment variables.