Error trying to connecto to a MySQL server

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?

RMySQL is a legacy package I think you should consider moving to the newer RMariaDB package (and driver).

Thanks. I have tried with this package too (after creating the question) and the error persist.

An additional thing I should say: I'm trying to access to a remote server. When I accessed to this database from workbench I had to do a tunnel with an SSH key. So maybe the error comes from this situation.

Yes, very likely, you have to create the ssh tunnel in advance, take a look at this example.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.