douqin0676 2014-01-21 07:46
浏览 93
已采纳

使用phpseclib通过SSH连接到MySQL的PHP​​代码

I want connect to MySQL on server, but the server only can be access with SSH. I use phpseclib to connect with SSH. And it was successfull. But when try connect to MySQL it said : Access Denied. So, I have these code. Anyone please help me..

<?php

//data for connection to SSH
//host : 10.81.229.31
//user : root
//pass : abcde

//here's data for connection to MySQL
//host = 10.81.229.31
//username = root
//password = abcde
//database name = testing


include('Net/SSH2.php');

//connecting to server with SSH
$ssh = new Net_SSH2('10.81.229.31');

if (!$ssh->login('root', 'abcde')) {
    exit('Login Failed');
}else{
    echo "Login Success";
}

//connecting to MySQL
echo $ssh->exec('mysql -h 10.81.229.31 -u root -p testing');

?>
  • 写回答

3条回答 默认 最新

  • douao3636 2014-01-21 20:22
    关注

    Try it without a space. eg.

    echo $ssh->exec('mysql -h localhost -u root -ptesting');
    

    Quoting from "man mysql":

    --password[=password], -p[password]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记