0

I have installed R3.0.1. Rtools is also installed. MySQL version 5.7 is installed. I want to connect R to MySQL, and I am trying to do that through RMySQL package in R. While the installation of RMySQL is finally done after looking at various SO questions, the library command gives error. Please see below complete R logs. Please help.

> install.packages("RMySQL",type="source")
trying URL 'http://cran.rstudio.com/src/contrib/RMySQL_0.9-3.tar.gz'
Content type 'application/x-gzip' length 165363 bytes (161 Kb)
opened URL
downloaded 161 Kb

* installing *source* package 'RMySQL' ...
** package 'RMySQL' successfully unpacked and MD5 sums checked
checking for $MYSQL_HOME... C:/Program Files/MySQL/MySQL Server 5.7
cygwin warning:
MS-DOS style path detected: C:/Program
Preferred POSIX equivalent is: /cygdrive/c/Program
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
test: Files/MySQL/MySQL: unknown operand
** libs
Warning: this package has a non-empty 'configure.win' file,
so building only the main architecture

cygwin warning:
MS-DOS style path detected: D:/SOFTWA~1/R-30~1.3/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/d/SOFTWA~1/R-30~1.3/etc/x64/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gcc -m64 -I"D:/SOFTWA~1/R-30~1.3/include" -DNDEBUG -I"C:/Program Files/MySQL/MySQL      Server 5.7"/include    -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -  std=gnu99 -mtune=core2 -c RS-DBI.c -o RS-DBI.o
RS-DBI.c: In function 'RS_na_set':
RS-DBI.c:1219:11: warning: variable 'c' set but not used [-Wunused-but-set-variable]
gcc -m64 -I"D:/SOFTWA~1/R-30~1.3/include" -DNDEBUG -I"C:/Program Files/MySQL/MySQL    Server 5.7"/include    -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  - std=gnu99 -mtune=core2 -c RS-MySQL.c -o RS-MySQL.o
RS-MySQL.c: In function 'RS_MySQL_fetch':
RS-MySQL.c:657:13: warning: variable 'fld_nullOk' set but not used [-Wunused-but-set- variable]
RS-MySQL.c: In function 'RS_DBI_invokeBeginGroup':
RS-MySQL.c:1137:30: warning: variable 'val' set but not used [-Wunused-but-set-variable]
RS-MySQL.c: In function 'RS_DBI_invokeNewRecord':
RS-MySQL.c:1158:20: warning: variable 'val' set but not used [-Wunused-but-set-variable]
RS-MySQL.c: In function 'RS_MySQL_dbApply':
RS-MySQL.c:1219:38: warning: variable 'fld_nullOk' set but not used [-Wunused-but-set-variable]
gcc -m64 -shared -s -static-libgcc -o RMySQL.dll tmp.def RS-DBI.o RS-MySQL.o C:/Program  Files/MySQL/MySQL Server 5.7/bin/libmySQL.dll - Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib  -LD:/SOFTWA~1/R-30~1.3/bin/x64 -lR
installing to D:/Softwares/R-3.0.3/library/RMySQL/libs/x64
** R
** inst
** preparing package for lazy loading
Creating a generic function for 'format' from package 'base' in package 'RMySQL'
Creating a generic function for 'print' from package 'base' in package 'RMySQL'
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
MYSQL_HOME defined as C:/Program Files/MySQL/MySQL Server 5.7 
* DONE (RMySQL)

The downloaded source packages are in
‘C:\Users\mitrabhanu.panda\AppData\Local\Temp\RtmpgZHT8R\downloaded_packages’

> library(RMySQL)
Looking in C:\Program Files/MySQL, C:/MySQL, D:/MySQL, E:/MySQL, F:/MySQL, G:/MySQL,   C:/xampp/MySQL, D:/xampp/MySQL, E:/xampp/MySQL, F:/xampp/MySQL, G:/xampp/MySQL,  C:/Apps/MySQL, D:/Apps/MySQL, E:/Apps/MySQL, F:/Apps/MySQL, G:/Apps/MySQL 
Found C:\Program Files/MySQL 
Error : .onLoad failed in loadNamespace() for 'RMySQL', details:
call: setwd(bin)
error: character argument expected
Error: package or namespace load failed for ‘RMySQL’

Please let me know what I have done wrong.

Marc Alff
  • 8,227
  • 33
  • 59
mitrabhanu
  • 389
  • 1
  • 2
  • 13
  • Why not use [RJDBC](http://cran.r-project.org/web/packages/RJDBC/index.html)? I will provide an example of retrieving records from mysql using it shortly as an answer. – hd1 Aug 31 '14 at 08:48
  • This has been answered many times on SO. e.g. http://stackoverflow.com/questions/23545796/another-error-when-installing-rmysql-in-windows-8-1?rq=1 – G. Grothendieck Aug 31 '14 at 10:23

1 Answers1

0

As written in my comment, here is the sample code for reading a table from mysql:

require(RJDBC)
j <- JDBC(classPath='/path/to/mysql/jdbc/jar', driverClass='com.mysql.jdbc.Driver')
connection <- dbConnect(j, 'jdbc:mysql://localhost/databasename', 'myusername','mypassword')
on.exit(dbDisconnect(connection))
data.frame.from.sql <- dbReadTable(connection, 'tablename')

This will read the table named tablename from databasename into data.frame.from.sql as an R data frame that you can manipulate as you see fit. I hope this helps.

hd1
  • 33,938
  • 5
  • 80
  • 91