Skip to content
Prev 247889 / 398503 Next

Accessing MySQL Database in R

The following worked for me recently:


library(RMySQL)
MySQL. <- MySQL()
MySQLcon <- dbConnect(MySQL., user='thisuser', password='thispassword',
                       dbname='desiredDB')


       I have the following suggestions and questions for you:


             1.  Have you tried supplying "dbname" rather than "host"?


             2.  Please provide "sessionInfo()".  Many packages have a 
function named "dbConnect", and I don't know which one you are using.


             3.  I don't know if "MySQL()" is equivalent to 
dbDriver("MySQL"), which you used.  It might be;  I don't know.


             4.  The standard "install.packages('RMySQL')" may not work, 
because this package needs to be built to configure itself properly to 
your local operating system and versions of MySQL and R installed.  
Installation instructions are available at 
"http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL".  If you have not 
already followed those instructions, please do so.  There is a good 
chance that will fix your problem, I think.


             5.  If this is not adequate, I suggest you post this 
question to "r-sig-db at stat.math.ethz.ch".  [I suggest you subscribe 
first.  This list has low volume and you can unsubscribe later if you 
prefer.  And please also provide "sessionInfo()".]


             6.  Or use RODBC as suggested by Ptit Bleu.  It comes 
highly recommended (including by Brian Ripley).  However, I had 
difficulties getting positive results from both RMySQL and RODBC.  I 
tried both, with each receiving similar quantities of expletives.  
Finally, I got RMySQL to do what I wanted and suspended my schoolboy 
exercises with RODBC.


       Hope this helps.
       Spencer
On 1/20/2011 5:55 AM, PtitBleu wrote: