Connect to MySQL from R

I initially attempted to install via:
sudo apt-get build-dep r-cran-rmysql

But I received an error trying to access MySQL from R:
Error in library(RMySQL) : there is no package called ‘RMySQL’

colin@mikrojenkins:~/mikroR$ cat installer.r
#!/usr/bin/r
install.packages(‘RMySQL’,type=’source’, repos=’http://cran.cnr.berkeley.edu/’)

*It hosed on me if I didn’t specify a repos arg*

Once RMySQL was installed, I was able to run my script:
#!/usr/bin/r
library(RMySQL)
con<-dbConnect(MySQL(), user='user', password='password', host='mikrodash.mikrodots.org', dbname='dashing') res<-dbGetQuery(conn = con, statement = "SELECT id, CAST(timestamp as CHAR(19)) as ts, count FROM opennonprojtix;") print(res) *Had to CAST the timestamp as CHAR ... RMySQL doesn't like the timestamp data type*

Leave a Reply

Your email address will not be published. Required fields are marked *