简体   繁体   English

无法从本地RStudio连接到MySQL数据库

[英]Unable to connect to MySQL Database from local RStudio

I want to connect to my enterprise MySQL server (APS) from RStudio local IDE. 我想从RStudio本地IDE连接到我的企业MySQL服务器(APS)。

However, I keep getting the following error message : 但是,我不断收到以下错误消息:

Error in .local(drv, ...) : Failed to connect to database: Error: Unknown MySQL Server Host '' (11001) .local(drv,...)中的错误:无法连接到数据库:错误:未知的MySQL Server主机''(11001)

I installed and loaded "RMySQL","DBI" and "dbConnect" packages and using the following code (sanitized): 我安装并加载了“ RMySQL”,“ DBI”和“ dbConnect”程序包,并使用以下代码(已清除):

drv <- dbDriver("MySQL")
dbname <- "DCA-APS-PRD"
user <- "<My_SSO_USERID>"
password <- "<My_SSO_PASSWORD>"
host <- "<prod server ip>"
port <- <prod server port>

con <- dbConnect(drv, user=user, password=password, dbname=dbname, host=host, port=port)

What am I doing wrong? 我究竟做错了什么?

First install the Connector/ODBC on your laptop, you can find it here: https://dev.mysql.com/downloads/connector/odbc/ 首先在笔记本电脑上安装连接器/ ODBC,您可以在这里找到: https : //dev.mysql.com/downloads/connector/odbc/

Then insert your connection parameters (User, IP, ...) in the connector and test it using the test button. 然后将连接参数(用户,IP,...)插入连接器,然后使用测试按钮对其进行测试。 If everything is ok, install the package RODBC in R: https://cran.r-project.org/web/packages/RODBC/index.html 如果一切正常,请在R中安装RODBC软件包: https ://cran.r-project.org/web/packages/RODBC/index.html

After that, test the connection, like this: 之后,测试连接,如下所示:

channel <- odbcConnect("connector", uid="user")
result  <-   paste("select * from table")
table<-sqlQuery(channel, result,error=TRUE)
table

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM