0

我已经安装了 R3.0.1。还安装了 Rtools。已安装 MySQL 5.7 版。我想将 R 连接到 MySQL,并且我正在尝试通过 R 中的 RMySQL 包来做到这一点。虽然在查看各种 SO 问题后终于完成了 RMySQL 的安装,但 library 命令给出了错误。请参阅下面的完整 R 日志。请帮忙。

> 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’

请让我知道我做错了什么。

4

1 回答 1

0

正如我在评论中所写,这是从 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')

这会将名为tablename的表从databasename读取到data.frame.from.sql作为R数据框,您可以根据需要对其进行操作。我希望这有帮助。

于 2014-08-31T08:52:38.800 回答