简体   繁体   English

使用 ssh 隧道连接的用户 'root'@'localhost' 的访问被拒绝(使用密码:YES)

[英]Access denied for user 'root'@'localhost' (using password: YES) using ssh tunnel connection

I'm using phpseclib to connect to mysql database with php for my app.我正在使用 phpseclib 连接到 mysql 数据库,并为我的应用程序使用 php。 I can connect to mysql with workbench using TCP/IP over SSH without a problem but I can't connect my code to it.我可以使用 TCP/IP over SSH 使用工作台连接到 mysql 没有问题,但我无法将我的代码连接到它。 I'm creating a ssh connection first and then I start with mysql connections and querys but I have this error我首先创建一个 ssh 连接,然后我从 mysql 连接和查询开始,但我有这个错误

mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (使用密码: YES)

I've found some people using a command like "$ssh->exec('mysql -u user -p password') to connect to mysql but after that, how can I do all my querys? as I understand, the "exec" command is as send commands to the server console?我发现有些人使用“$ssh->exec('mysql -u user -p password') 之类的命令连接到 mysql 但在那之后,我怎样才能完成所有查询?据我所知,“exec " 命令是作为向服务器控制台发送命令吗?

Here is my code, I hope you can help me: This is conexion.php这是我的代码,希望你能帮助我:这是conexion.php

include('Net/SSH2.php');
include('remote_conexion.php');

$db_host="127.0.0.1"; 
$db_user="root";
$db_password=" ";
$db_name="mascotas"; 
$ssh = new Net_SSH2($host);
if (!$ssh->login($sftp_user, $sftp_password)) {
    exit('Login Failed');
}
$connection = mysqli_connect($db_host, $db_user, $db_password, $db_name);

And this is remote_conexion.php (ignore the "sftp" things, I'm using that for manage files)这是remote_conexion.php (忽略“sftp”的东西,我用它来管理文件)

include('Net/SFTP.php');
$host="***.***.**.***";              
$sftp_user="user";              
$sftp_password="*******";   
$port="22";

   $sftp = new Net_SFTP($host);
if (!$sftp->login($sftp_user, $sftp_password)) {
    exit('Login Failed');
}

phpseclib doesn't (currently) support tunneling. phpseclib(当前)不支持隧道。 And even if it did you wouldn't be able to use mysqli_connect - you'd have to have a pure-PHP MySQL implementation, kinda like https://github.com/amphp/mysql .即使这样做,您也无法使用mysqli_connect - 您必须有一个纯 PHP MySQL 实现,有点像https://github.com/amphp/mysql

In lieu of that the best you're gonna be able to do (with phpseclib) is something like this:取而代之的是,你能做的最好的事情(使用 phpseclib)是这样的:

echo $ssh->exec('mysql -uUSER -pPASSWORD DATABASE -e "SQL COMMAND"');

connect to the mysql database using phpseclib library talks about how to improve on that slightly but even with that you're not going to be able to make use of (for example) prepared statements or even mysqli_real_escape_string .使用 phpseclib 库连接到 mysql 数据库讨论了如何稍微改进它,但即使这样,您也无法使用(例如) 准备好的语句甚至mysqli_real_escape_string

The best solution, imho, would be to use something like AutoSSH恕我直言,最好的解决方案是使用AutoSSH 之类的东西

I've read all your answers and I tried to connect from the traditional way, without using the ssh functions.我已阅读您的所有答案,并尝试以传统方式连接,而不使用 ssh 函数。 Just like this:像这样:

 $connection = mysqli_connect($host, $db_user, $db_password, $db_name);

Using the server ip as "host", the username and password from mysql but I got this message now:使用服务器 ip 作为“主机”,来自 mysql 的用户名和密码,但我现在收到此消息:

mysqli_connect(): (HY000/2002):An error occurred during the connection attempt since the connected party does not respond after a period of time, or an established connection error occurred that the connected host has not responded. mysqli_connect(): (HY000/2002):连接尝试时出错,因为连接方一段时间没有响应,或者连接主机没有响应建立连接错误。

This way works when I'm using localhost, but not in this case with the remote server.这种方式在我使用 localhost 时有效,但在这种情况下不适用于远程服务器。 All the login data it's ok, I can connect to database via workbench without a problem (I have to connect with workbench using TCP/IP over SSH) but I don't know why I can't connect with php.所有登录数据都可以,我可以通过工作台毫无问题地连接到数据库(我必须通过 SSH 使用 TCP/IP 与工作台连接)但我不知道为什么我无法连接到 php。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用MAMP拒绝用户'root'@'localhost'的访问(使用密码:是) - Access denied for user 'root'@'localhost' (using password: YES) using MAMP 用户 'root'@'localhost' 的访问被拒绝(使用密码:YES)' - Access denied for user 'root'@'localhost' (using password: YES)' 用户'root'@'localhost'的访问被拒绝(使用密码:是) - Access denied for user 'root'@'localhost' (using password: YES) #1045-用户'root'@'localhost'的访问被拒绝(使用密码:是) - #1045 - Access denied for user 'root'@'localhost' (using password: YES) laravel 5用户“ root” @“ localhost”的访问被拒绝(使用密码:是) - laravel 5 Access denied for user 'root'@' localhost' (using password: YES) 连接失败:用户 ''username'@'localhost' 访问被拒绝(使用密码:YES) - Connection failed: Access denied for user ''username'@'localhost' (using password: YES) 重置 root 密码后,用户 'root'@'localhost' 的访问被拒绝(使用密码:YES) - Access denied for user 'root'@'localhost' (using password: YES) after resetting root password 数据库连接错误用户'root'@'localhost'的访问被拒绝(使用密码:否) - Database connection error Access denied for user 'root'@'localhost' (using password: NO) xampp localhost phpmyadmin 用户 'root'@'localhost' 访问被拒绝(使用密码:YES) - xampp localhost phpmyadmin Access denied for user 'root'@'localhost' (using password: YES) 用户'root'@'localhost'的访问被拒绝(使用密码:NO) - Access denied for user 'root'@'localhost' (using password: NO)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM