dow72046 2011-05-12 15:24
浏览 45
已采纳

Phpseclib连接MYSQL服务器

I want to connect to my remote MySQL server through port forwarding. Unfortunately my hosting provider don't have php_ssh2 installed on the server so I have to work through phpseclib library. So far I am able to do:

1 - Connect to server using Net_SSH2:

$ssh = new Net_SSH2('xx.xxx.xx.xx');  
 if (!$ssh->login('user', 'password')) {  
    exit('Login Failed');  
 }  

If I do echo $ssh->exec('ls -la');, it fetches directory listing telling we are connected successfully.

if I run

2 - echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql');

It triggers:

stdin: is not a tty ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO)

3 - If I do echo $ssh->exec('ssh -f -L 3307:localhost:3306 root@xx.xxx.xxx.xxx sleep 60 >> logfile');

It runs forever resulting in no response error from the server.

I am pulling my hair out. HELP!!!!!

  • 写回答

1条回答 默认 最新

  • dongmubei7950 2011-05-18 12:30
    关注

    Maybe try this?:

    echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql -u username -password=password database');
    

    As is it's probably waiting for a password to be entered.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页