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
install.packages(‘RMySQL’,type=’source’, repos=’’)

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

Once RMySQL was installed, I was able to run my script:
con<-dbConnect(MySQL(), user='user', password='password', host='', 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 *