简体   繁体   English

R SSH tunnel to MySQL database via Shiny App Access Denied or Can't connect to MySQL server on '127.0.0.1'

[英]R SSH tunnel to MySQL database via Shiny App Access Denied or Can't connect to MySQL server on '127.0.0.1'

I've looked through other posts without success, so here we are.我已经浏览了其他帖子但没有成功,所以我们到了。 The following code snippet runs as expected on a Windows 10 laptop in RStudio.以下代码片段在 RStudio 中的 Windows 10 笔记本电脑上按预期运行。

library(RMySQL)
library(ssh)
library(callr)

rs <- r_session$new(wait = TRUE, wait_timeout = 3500)

rs$call(function(){
  session <- ssh::ssh_connect('<ssh-user>@<remote-ip-address>', keyfile = "<path-to-.pem-file>", verbose = FALSE)
  
  ssh::ssh_tunnel(session, port=3306, target = "127.0.0.1:3306")
})

# Connect to TRAQ DB.
Sys.sleep(1)

db-connection <- dbConnect(MySQL(), user = '<remote-user-name>', password = '<remote-password>', dbname = '<remote-database>', port=3306, host='127.0.0.1')

The snippet runs runs successfully too when dbConnect() has host='localhost'当 dbConnect() 具有 host='localhost' 时,该代码段也会成功运行


I am attempting to run the snippet on a virtual machine running Ubuntu 22 within an R shiny app.我正在尝试在 R shiny 应用程序中运行 Ubuntu 22 的虚拟机上运行该片段。 I receive the following messages while trying to load the app我在尝试加载应用程序时收到以下消息

Using localhost:使用本地主机:

ERROR 1044 (42000): Access denied for user '<remote-user-name>'@'localhost'

Using 127.0.0.1:使用 127.0.0.1:

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

I have received the (115) error code too.我也收到了(115)错误代码。


If run directly from the R terminal, the snippet must be modified as follows for success.如果直接从 R 终端运行,则必须将代码段修改如下才能成功。

ssh::ssh_tunnel(session, port=3306, target = "127.0.0.1:3306")

to

ssh::ssh_tunnel(session, port=3307, target = "127.0.0.1:3306")

AND

db-connection <- dbConnect(MySQL(), user = '<remote-user-name>', password = '<remote-password>', dbname = '<remote-database>', port=3306, host='127.0.0.1')

to

db-connection <- dbConnect(MySQL(), user = '<remote-user-name>', password = '<remote-password>', dbname = '<remote-database>', port=3307, host='127.0.0.1')

If the host is set to 'localhost' or ports are left at 3306, an Access denied message is displayed.如果主机设置为“localhost”或端口保留为 3306,则会显示拒绝访问消息。


Unclear if this is due to a MySQL discrepancy or an operating system discrepancy.不清楚这是由于 MySQL 差异还是操作系统差异造成的。 I don't believe it to be an issue on the remote server being SSH'd into since it works on the Windows laptop.我不认为这是通过 SSH 连接到的远程服务器上的问题,因为它可以在 Windows 笔记本电脑上运行。

select user,host from mysql.user; select 用户,主机来自 mysql.user; Check your legal username and host and replace it.检查您的合法用户名和主机并替换它。 In addition, there is a difference between 127.0.0.1 and localhost.另外,127.0.0.1 和 localhost 是有区别的。 You should pay attention to whether the /etc/hosts file is mapped.您应该注意/etc/hosts 文件是否被映射。

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

相关问题 SSH 隧道与 R 错误:无法连接到数据库:错误:无法连接到 MySQL 服务器在“115.0.0.1”() - SSH Tunnel with R error: Failed to connect to database: Error: Can't connect to MySQL server on '127.0.0.1' (115) MySQL通过SSH隧道访问被拒绝 - MySQL via SSH Tunnel Access Denied 使用 SSH 隧道“无法连接到本地 MySQL 服务器” - "Can't connect to local MySQL Server" using SSH tunnel 无法连接到AWS上的远程MySQL服务器,但ssh隧道可以正常工作 - Can't connect to remote MySQL server on AWS, but ssh tunnel works mysql 无法连接 SSH 隧道 -> 拒绝“无”访问 - mysql could not connect the SSH tunnel -> access denied for 'none' Python脚本通过SSH隧道连接到Namecheap上的MySQL数据库 - Python script to connect via SSH tunnel to MySQL database at Namecheap PhpStorm 不会通过 SSH 隧道连接到远程 MySQL - PhpStorm won't connect to remote MySQL via SSH tunnel 如何通过SSH隧道将PHP / Codeigniter应用程序连接到远程MySQL数据库? - How can I connect a PHP/Codeigniter application to a remote MySQL database via SSH tunnel? 通过ssh隧道连接到MySQL到localhost - Connect to MySQL via ssh tunnel to localhost 无法连接到“ 127.0.0.1”上的MySQL服务器 - Can't Connect to MySQL server on '127.0.0.1'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM