Reputation: 7928
I want to connect to a MySQL database from R and I'm having some troubles. It is impossible to provide a reproducible example, but I hope someone can spot any mistake that I might be making.
This is the code I'm running in R:
library(methods)
library(DBI)
library(RMySQL)
DB_name = "myDBname"
drv <- dbDriver("MySQL")
con <- dbConnect(drv, user="myUser", password="myPassword", dbname="myDBname",
host="my.host.something")
This is the error that I get:
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Can't connect to MySQL server on 'my.host.something' (110)
I'm able to connect from the command line without any problem.
Thanks!
Upvotes: 1
Views: 2215
Reputation: 7928
First, create a conf file
gedit ~/.my.cnf
[someName]
user = myUser
password = myPassword
host = my.host.something
port=3306
Second, In R
library(methods)
library(DBI)
library(RMySQL)
DB_name = "myDBname"
drv <- dbDriver("MySQL")
con <- dbConnect(drv, group= "someName", dbname=DB_name)
Upvotes: 2