使用Java代码关闭mysql服务器的方法
Java代码如下:
package com.jy.pub;
import java.io.IOException;
import com.jy.base.BaseAction;
import com.jy.util.StringUtil;
public class Startmysql extends BaseAction{
private static Startmysql instance =null ;
private Startmysql(){
}
public static Startmysql getInstance(){
if(instance == null){
logger.info("创建instance...");
instance = new Startmysql();
}
return instance ;
}
public void stop(){
try {
logger.info("关闭mysql服务...");
Runtime.getRuntime().exec("cmd /c start net stop mysql");
logger.info("关闭mysql服务成功...");
} catch (IOException e) {
logger.info("关闭mysql服务失败...");
e.printStackTrace();
}
}
public void backup(){
try {
logger.info("备份数据库...");
String path = new StringUtil().getWebRoot()+"bat/backup.bat";
Runtime.getRuntime().exec("cmd /c "+path);
logger.info("备份数据库成功...");
} catch (IOException e) {
logger.info("备份数据库失败...");
e.printStackTrace();
}
}
public static void main(String args[]) throws IOException{
Startmysql.getInstance().start();
//Startmysql.getInstance().stop();
}
}
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: java xstream可以压缩数据吗