php 操作linux下的mysql开启关闭
来源:互联网 发布:2016年济南市酒驾数据 编辑:程序博客网 时间:2024/04/28 03:20
<?php
header('content-type:text/html;charset=utf8');
$status = $_GET['status'];
$host=“写自己的”';//被控制的linux的ip
$user='写自己的';//用户名
$passwd='写自己的';//密码
// 链接远程服务器
$connection = ssh2_connect($host, 22);
if (!$connection) die('connection to '.$host.':22 failed');
//echo 'connection OK<br/>';
// 获取验证方式并打印
$auth_methods = ssh2_auth_none($connection, $user);
//print_r( $auth_methods.'<br/>');
if (in_array('password', $auth_methods ))
{
// 通过password方式登录远程服务器
if (ssh2_auth_password($connection, $user, $passwd))
{
//echo $user.' login OK<br/>';
$stream = ssh2_exec($connection, "pwd"); // 执行php
stream_set_blocking($stream, true); // 获取执行pwd后的内容
/*$stream = ssh2_exec($connection, "ls");
echo 'pwd: '.stream_get_contents($stream).'<br/>';*/
//$stream = ssh2_exec($connection, "ls");
//echo 'pwd: '.stream_get_contents($stream).'<br/>';
if($status == 0){
$stream = ssh2_exec($connection, "service mysqld stop"); // 执行php
}else if($status == 1){
$stream = ssh2_exec($connection, "service mysqld start"); // 执行php
}
$c = @mysql_connect($host,'root','root');
//var_dump(@mysql_connect($host,'root','root'));die;
if($c){
$a = 1;
}else{
$a = 0;
}
//$stream = ssh2_exec ( $connection , 'shutdown -h -now' );
//if ($stream === FALSE) die("pwd failed");
}
else
{
die( $user.' login Failed<br/>');
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<table>
<tr>
<td>主机昵称</td>
<td>IP地址</td>
<td>mysql服务状态</td>
<td>操作</td>
</tr>
<tr>
<td><?php echo $user;?></td>
<td><?php echo $host;?></td>
<td><?php
if($a == 1){
echo "开启";
}else{
echo "关闭";
}
?> </td>
<td>
<?php
if($a == 1){
echo "<a href='yuekao.php?status=0'>关闭</a>";
}else{
echo "<a href='yuekao.php?status=1'>开启</a>";
}
?>
</td>
</tr>
</table>
</body>
header('content-type:text/html;charset=utf8');
$status = $_GET['status'];
$host=“写自己的”';//被控制的linux的ip
$user='写自己的';//用户名
$passwd='写自己的';//密码
// 链接远程服务器
$connection = ssh2_connect($host, 22);
if (!$connection) die('connection to '.$host.':22 failed');
//echo 'connection OK<br/>';
// 获取验证方式并打印
$auth_methods = ssh2_auth_none($connection, $user);
//print_r( $auth_methods.'<br/>');
if (in_array('password', $auth_methods ))
{
// 通过password方式登录远程服务器
if (ssh2_auth_password($connection, $user, $passwd))
{
//echo $user.' login OK<br/>';
$stream = ssh2_exec($connection, "pwd"); // 执行php
stream_set_blocking($stream, true); // 获取执行pwd后的内容
/*$stream = ssh2_exec($connection, "ls");
echo 'pwd: '.stream_get_contents($stream).'<br/>';*/
//$stream = ssh2_exec($connection, "ls");
//echo 'pwd: '.stream_get_contents($stream).'<br/>';
if($status == 0){
$stream = ssh2_exec($connection, "service mysqld stop"); // 执行php
}else if($status == 1){
$stream = ssh2_exec($connection, "service mysqld start"); // 执行php
}
$c = @mysql_connect($host,'root','root');
//var_dump(@mysql_connect($host,'root','root'));die;
if($c){
$a = 1;
}else{
$a = 0;
}
//$stream = ssh2_exec ( $connection , 'shutdown -h -now' );
//if ($stream === FALSE) die("pwd failed");
}
else
{
die( $user.' login Failed<br/>');
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<table>
<tr>
<td>主机昵称</td>
<td>IP地址</td>
<td>mysql服务状态</td>
<td>操作</td>
</tr>
<tr>
<td><?php echo $user;?></td>
<td><?php echo $host;?></td>
<td><?php
if($a == 1){
echo "开启";
}else{
echo "关闭";
}
?> </td>
<td>
<?php
if($a == 1){
echo "<a href='yuekao.php?status=0'>关闭</a>";
}else{
echo "<a href='yuekao.php?status=1'>开启</a>";
}
?>
</td>
</tr>
</table>
</body>
</html>
注意事项:
1. linux为centos6.4(如果为centos7的话只需更改启动和关闭的语法)
2.记得为linux下mysql的远程赋权
0 0
- php 操作linux下的mysql开启关闭
- Linux下开启/关闭MySql Server
- Linux下开启/关闭MySql Server命令
- Linux下开启/关闭MySql Server命令
- Linux下开启/关闭MySql Server命令
- Linux下开启/关闭MySql Server
- linux下mysql开启/关闭远程访问
- linux下端口的开启和关闭
- Linux下mysql数据库开启操作日志
- linux下PHP错误警报开启与关闭
- Linux下关闭开启防火墙
- Linux下开启关闭防火墙
- Linux下开启关闭防火墙
- Linux下的MySQL简单操作(服务启动与关闭、启动与关闭、查看版本)
- Linux下开启MySQL的远程连接
- linux 下 开启 MySQL的binlog
- Linux下开启MySQL的远程连接
- Linux下关闭和开启IPv6的方法
- 利用FreeType让LibGDX输出中文
- 机器学习(周志华)西瓜数据集3.0
- java线程池
- 【转】欢迎使用CSDN-markdown编辑器
- 8.5Recursive Multiply
- php 操作linux下的mysql开启关闭
- 最小生成树 (tarjan 求桥)
- 欢迎使用CSDN-markdown编辑器
- C#中Dictionary和HashTable的相同点与不同点(今天又看到了HashSet,所以补充一下)
- 自定义makefile
- Hive on Spark安装配置详解
- 位运算入门应用及技巧
- qt QTabWidget
- 随机数去重排序