首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

用php装配mysql服务

2012-08-29 
用php安装mysql服务function __MysqlStart(){$cmd net start mysqlexec($cmd, $o, $r)$o join(\n,

用php安装mysql服务

function __MysqlStart(){    $cmd= "net start mysql";    exec($cmd, $o, $r);    $o= join("\n", $o);    if($this->debug){        $this->log(__METHOD__, __LINE__, "$cmd ==> \n".$o);    }    if( empty($r)  ){        //preg_match("/服务已经启动成功/", $o)        return true;    }else{        //throw new Exception($r);        return false;    }}    function __MysqlStop(){    $cmd= "net stop mysql";    exec($cmd, $o, $r);    $o= join("\n", $o);    if($this->debug){        $this->log(__METHOD__, __LINE__, "$cmd ==> \n".$o);    }    if( empty($r)  ){        //preg_match("/服务已经启动成功/", $o)        return true;    }else{        return false;        //throw new Exception($r);    }}    function __MysqlRemove(){    $stat= $this->__query('mysql');    if($this->debug){        $this->log(__METHOD__, __LINE__, "mysql status = $stat");    }    if( $stat === 'start' ){        $this->__MysqlStop();    }        $cmd= MysqlDir.'\bin\mysqld-nt.exe --remove mysql';    exec($cmd, $r);    $r= join("\n",$r);    if($this->debug){        $this->log(__METHOD__, __LINE__, "$cmd ==> \n".$r);    }    if( preg_match("/successfully/", $r) ){        unset($this->ports['mysql']);        return true;    }else{        return false;    }}function __MysqlInstall(){    $this->__MysqlRemove();        $port= $this->__getFreePort(3306, 'mysql');    $this->ports['mysql']= $port;        $this->__etc( 'mysql.ini', MysqlDir.'\my.ini' , array(            '%port%' => $port,            '%root%' => uRootDir        ));    $cmd= MysqlDir.'\bin\mysqld-nt.exe  --install mysql  --defaults-file="'.MysqlDir.'\my.ini"';    exec($cmd, $r);    $r= join("\n",$r);    if($this->debug){        $this->log(__METHOD__, __LINE__, "$cmd ==> \n".$r);    }    if( !preg_match("/successfully/", $r) ){        throw new Exception("安装mysql失败");    }    }

热点排行