温馨提示×

用代码怎么关闭mysql服务器

九三
234
2021-02-11 08:13:05
栏目: 云计算

用代码怎么关闭mysql服务器

使用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();

}

}

0