R - Error trying to connect to a MySQL server

Viewed 64

I'm trying to connect to a MySQL database using this code:

con <- dbConnect(RMySQL::MySQL(),
             dbname = "XX",
             host = "YY",
             port = ZZ,
             user = "AA",
             password = "BB"
             )

And I'm getting this error:

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

I've tried with this other code:

pool <- dbPool(drv = RMySQL::MySQL(), 
           dbname = "XX", 
           host = "YY", 
           username = "AA", 
           password = "BB", 
           port = ZZ
           )

And get the same error:

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

I can connect to this database using Workbench, so I guess it's a problem with R.

Any solution to this problem?

Edit: something I didn't say, the server is remote, so I had to use a SSH key to make the tunnel to the server to be able to access from Workbench. So maybe this should be considered to solve the issue.

0 Answers
Related