我是 R 的新手,我正在尝试将 R 与 MySQL 连接起来。我已经安装mysql-5.5.22-winx64
了R-2.12.0
64 位。我已经设置MYSQL_HOME environment path(C:\Program Files\MySQL\MySQL Server 5.5)
并尝试执行以下步骤:
- 从这里安装最新的 RTools
- 安装mysql或者mysql的头文件和库文件
- 创建或编辑文件
C:\Program Files\R\R-2.12.1\etc\Renviron.site
并添加类似MYSQL_HOME=C:/mysql
的行(mysql文件的路径) - 复制
libmysql.lib
frommysql/lib
tomysql/lib/opt
以满足依赖关系。 - 复制
libmysql.dll
到C:\Program Files\R\R-2.12.1\bin
或 到windows/system32 directory
。 运行
install.packages('RMySQL',type='source')
并等待编译将结束。但我仍然收到此错误:-*> install.packages('RMySQL',type='source') --- Please select a CRAN mirror for use in this session --- trying URL 'http://ftp.iitm.ac.in/cran/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' ... ERROR: configuration failed for package 'RMySQL' * removing 'C:/PROGRA~1/R/R-212~1.0/library/RMySQL' * restoring previous 'C:/PROGRA~1/R/R-212~1.0/library/RMySQL' The downloaded packages are in ‘C:\Users\sharad\AppData\Local\Temp\RtmpdQHwCb\downloaded_packages’ Warning message: In install.packages("RMySQL", type = "source") : installation of package 'RMySQL' had non-zero exit status*
请建议我如何解决这个问题?
最后我得到了解决方案:-您可以在我的博客上详细查看解决方案。
我最近两天一直在用 RMySQL 包安装 R,终于找到了解决方案,这里是安装 RMySQL 包的步骤:-
从以下链接下载软件:
* a. R2.13.2: Download R from http://cran.stat.sfu.ca/index.html b. RTools 214: Download RTools from http://cran.cict.fr c. RMySQL 0.8-0.tar.gz: Download RMySQL from http://biostat.mc.vanderbilt.edu/wiki/main/RMySQL/RMySQL_0.8-0.tar.gz d. MySQL Server 5.0: download it from http://dev.mysql.com e. RSTUDIO (optional): download it from http://rstudio.org*
设置以下环境变量
* a. MYSQL_HOME : <drive>/path to MySQL installation folder e.g. MYSQL_HOME= C:\Program Files\MySQL\MySQL Server 5.5\ b. R_HOME: <drive>/path to R installation e.g. R_HOME=C:\Program Files\R\R-2.13.2\ c. PATH: Modify path to accommodate the above variables. *
确保 Windows PATH 变量中包含以下路径: \Rtools\2.14\bin \Rtools\2.14\MinGW\bin \Rtools\2.14\MinGW64\bin
创建文件夹并复制文件
* a. OPT: Create a folder OPT under C:\Program Files\MySQL\MySQL Server 5.5\lib and copy MYSQLLIB.LIB the above path. Also copy libmysql.dll to <drive>\<path>\R\R-2.14.0\bin\(64 bit) Or <Drive>\<path>\R\R-2.14.0\bin\i386\ (32 bit) and to C:\Windows\System32. b. Renviron.site: create or edit a file <DRIVE>\<path>\R\R-2.14.0\etc\Renviron.site and add a line: MYSQL_HOME =”C:/Program Files/MySQL/MySQL Server 5.5/” NB: USE FORWARD SLASH AND DOUBLE QUOTES HERE c. libMySQL.dll: Copy this file to C:\Program Files\R\R-2.13.2\bin\i386 as well as C:\Program Files\R\R-2.13.2\bin*
运行命令
一种。Install.Packages:通过单击桌面上的 R 图标或从开始菜单运行 R GUI。键入 INSTALL.PACKAGES(“RMySQL”,type="Sources")。 这将从存储库下载所需的软件。
湾。命令提示符:复制下载的 zip 文件(在步骤 4.a.中)并将其粘贴到 R 安装文件夹下。转到开始菜单并打开命令提示符。转到 R 安装文件夹并键入 R CMD INSTALL RMySQL_0.8-0.tar.gz
*命令:
library(RMySQL) drv = dbDriver("MySQL") con = dbConnect(drv,host="localhost",dbname="test",user="root",pass="root") 专辑 = dbGetQuery(con,statement= “从 t_master 中选择 *”)专辑*