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 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画