3

I'm learning R language. I want to establish a connection with MySQL using R. I've studied how to do from here, here, tutorial and from many other websites. I've followed all the steps to connect with MySQL, but still I'm unable to connect with MySQL, and getting an error:

 Error in .local(drv, ...) : Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0) 

Here is screenshot of what I did: work done and error

I'm using R version-3.2.2 and MySQL version-5.6 and MySQL database is running on localhost:1527. Please help me to remove the error and tell me what I'm doing wrong.

INFO: I'm able to connect above MySQL database with java.

9
  • 2
    Please read this SO post, as there appears to be a bit more configuration than what you have done above. Commented Sep 30, 2015 at 6:42
  • 1
    Intuitively, it should make sense that the R package won't know where to look for your MySQL database out of the box without you telling it where to look. Commented Sep 30, 2015 at 6:42
  • Do you mean I've to set classpath variables. (Sorry for asking silly question) Commented Sep 30, 2015 at 6:45
  • 1
    Your question isn't silly actually. Yes, I believe you have to configure some environment variables. Work through that post and then come back here if you still can't get it to work. It's good that your JDBC code works, because at least we know that there is nothing wrong with your MySQL instance. Commented Sep 30, 2015 at 6:46
  • 1
    maybe run Sys.getenv() to see the MySQL path Commented Sep 30, 2015 at 7:10

1 Answer 1

2

you say that your mysql is running on localhost:1527 - but you don't specify that port in dbConnect, then it probably uses the default port, 3306, so it should not be able to connect... add the port argument to your dbConnect

dbConnect(MySQL(), user="user", password="password", dbname="dbname", host="localhost", port="1527") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.