简体   繁体   中英

R - connecting to remote mysql server

I am trying to connect in R to remote mysql server, but without success.

That is my code -

library(RMySQL)
drv = dbDriver("MySQL")
mydb = dbConnect(drv,host="*.*.*.*",dbname="dbname",user="user",pass="pass")

but I get the following error -

Failed to connect to database: Error: Access denied for user 'user'@'ec2- - - - .eu-west-1.compute.amazonaws.com'

It is trying to connect to local host, and not the host I specified in the code.

What is wrong?

Looks to me like you haven't granted proper access for this user where queries are coming from ec2----.eu-west-1.compute.amazonaws.com.

Try something like:

CREATE USER 'user'@'ec2----.eu-west-1.compute.amazonaws.com' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON dbname.* TO 'user'@'ec2----.eu-west-1.compute.amazonaws.com';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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