phpseclib连接MYSQL服务器 [英] Phpseclib connect MYSQL server
问题描述
我想通过端口转发连接到我的远程MySQL服务器.不幸的是,我的托管服务提供商没有在服务器上安装php_ssh2
,因此我必须通过phpseclib
库工作.到目前为止,我能够做到:
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-使用Net_SSH2
连接到服务器:
1 - Connect to server using Net_SSH2
:
$ssh = new Net_SSH2('xx.xxx.xx.xx');
if (!$ssh->login('user', 'password')) {
exit('Login Failed');
}
如果执行echo $ssh->exec('ls -la');
,它将获取目录列表,表明我们已成功连接.
If I do echo $ssh->exec('ls -la');
, it fetches directory listing telling we are connected successfully.
如果我运行
2-echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql');
它触发:
stdin:不是tty错误1045(28000):用户被拒绝访问 '用户'@'本地主机'(使用密码:否)
stdin: is not a tty ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO)
3-如果我执行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!!!!!
推荐答案
也许试试看?:
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.
这篇关于phpseclib连接MYSQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!