Skip to content
Prev 247580 / 398503 Next

Accessing MySQL Database in R

I have a local installation of MySQL on my computer.

I enter the following to access MySQL from the command line:
/Applications/MAMP/Library/bin/mysql -h localhost -u root -p
I am then prompted for a password, and I use: root
This connects me to MySQL in the command line.

I now want to access MySQL databases in R. I enter the following: 
mysql <- dbDriver("MySQL")
conn <- dbConnect(mysql,user='root',host='localhost', password='root')

I get the following error message: Error in mysqlNewConnection(drv, ...) : 
RS-DBI driver: (Failed to connect to database: Error: Access denied for user
'root'@'localhost' (using password: YES)

Does anyone know why these aren't equivalent?