This works perfectly fine in R (using RStudio IDE):
library(RMySQL)
con <- dbConnect(RMySQL::MySQL(),
dbname="remote_db_name",
user = "root",
password = "remote_pw",
host = "remote_host.rds.amazonaws.com"
)
Obviously, for best practices, I decided to move the connection details to a file(myconfig.cnf)
The contents of myconfig.cnf
# Config file to connect to the remote DB
[production]
dbname=remote_db_name
user=root
password=remote_pw
host=remote_host.rds.amazonaws.com
And I run this code in R now:
con1 <- dbConnect(RMySQL::MySQL(), group='production',default.file="~full_path/myconfig.cnf")
But on execution, I get the error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Access denied for user 'root'@'my_public_ip' (using password: YES)
I am clueless now. The code that works when you hardcode it, but not when you provide it in a config file.
Any suggestions on how to fix this and explain what's happening under the hood?
Thanks, Rouse