Skip to content
Prev 247859 / 398503 Next

Accessing MySQL Database in R

Hello,

I used to use RMySQL but as there is no more package for windows, I decided
to move to RODBC.
I installed ODBC driver for MySQL (downloaded on the MySQL website) and then
the RODBC package.

I finally discovered that it was not needed to "register" your database with
ODBC before using it.
These commands below work for me.

library(RODBC)
ch<-odbcDriverConnect(connection="SERVER=localhost;DRIVER=MySQL ODBC 5.1
Driver;DATABASE=my_database;UID=root;PWD=my_password;case=tolower")
resultdb<-sqlQuery(ch,"SELECT * from my_table")
odbcClose(ch)

Try to modify them for your case.
I hope it will work for you.
Good luck,
Ptit Bleu.


Re: Accessing MySQL Database in R
Jan 18, 2011; 12:10am ? by djmuseR [User is online] djmuseR
Hi:

Because R does not have a direct interface to MySQL?

You need to load a communication package - the two most common ones are
RODBC and RMySQL. The former requires that you register your MySQL database
table(s) with ODBC before using the RODBC package on them, whereas the
latter works with specific version combinations of MySQL and R. The RODBC
package has a very informative vignette; for information re the RMySQL
package, see
http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL

HTH,
Dennis
On Mon, Jan 17, 2011 at 1:30 PM, schlafly <[hidden email]> wrote: