I'm trying to set up the initial database connection between R and MySQL. I installed RMySQL. When I try to connect to my database, this is the error I receive.
Any direction in fixing it is much appreciated! The package is still quite new so help on this is a little difficult to find. (I'm also new to R).
con <- dbConnect(RMySQL::MySQL(), group = "Mydatabase")
Error in .local(drv, ...) Failed to connect to database Error: Can't connect to MySQL server on 'localhost' (0)
You have to make sure you have a proper MySQL database set up and you need to pass the config options of that database to the
dbConnect
call. Is there a MySQL database on that machine?I think if you use the
group
parameter, thenRMySQL
will assume you have a configuration file with settings for aMydatabase
database. I forget how to set up that file, but this is how I connect toRMySQL
:(in my .Rprofile I set up all these options). After you have all these values (dbname, host, port, user, pw) for your database, try running this command