在 Windows 的 R 中使用 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5223113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using MySQL in R for Windows
提问by Yuriy Petrovskiy
How to use MySQL in R (statistic language) for Windows (7)?
如何在 Windows (7) 的 R(统计语言)中使用 MySQL?
There is no problems then using linux:
那么使用linux就没有问题了:
install.packages('RMySQL')
library(RMySQL)
...
But I found no such package for Windows on CRAN. There is only noteabout this fact. I found package for version 2.10, but it is not usable in 2.12.1.
但是我在 CRAN 上没有发现适用于 Windows 的此类软件包。关于这个事实只有注释。我找到了 2.10 版的包,但它在 2.12.1 中不可用。
Also tried
也试过
install.packages("RMySQL", type="source")
but got an error :
但出现错误:
* installing *source* package 'RMySQL' ...
ERROR: configuration failed for package 'RMySQL'
* removing 'C:/.../R/win-library/2.12/RMySQL'
Is there any way to connect to MySQL database from R in windows?
有什么办法可以从 Windows 中的 R 连接到 MySQL 数据库吗?
采纳答案by Yuriy Petrovskiy
Found solution with help of ran2, who gave me link to common question. The basic process is described here, but there are several hints, So I will describe the whole solution (please change the R version and paths if needed):
在ran2的帮助下找到了解决方案,他给了我常见问题的链接。这里描述了基本过程,但有几个提示,所以我将描述整个解决方案(如果需要,请更改R版本和路径):
- Install latest RTools from here
- install MySQL or header and library files of mysql
- create or edit file
C:\Program Files\R\R-2.12.1\etc\Renviron.site
and add line likeMYSQL_HOME=C:/mysql
(path to your mysql files) - copy libmysql.lib from mysql/lib to mysql/lib/opt to meet dependencies.
- copy libmysql.dll to
C:\Program Files\R\R-2.12.1\bin
or towindows/system32
directory. - run
install.packages('RMySQL',type='source')
and wait while compilation will end.
- 从这里安装最新的 RTools
- 安装 MySQL 或 mysql 的头文件和库文件
- 创建或编辑文件
C:\Program Files\R\R-2.12.1\etc\Renviron.site
并添加类似行MYSQL_HOME=C:/mysql
(mysql 文件的路径) - 将 libmysql.lib 从 mysql/lib 复制到 mysql/lib/opt 以满足依赖项。
- 将 libmysql.dll 复制到
C:\Program Files\R\R-2.12.1\bin
或windows/system32
目录。 - 运行
install.packages('RMySQL',type='source')
并等待编译结束。
Thanks to all who tried to answer.
感谢所有试图回答的人。
回答by Matt Bannert
回答by Ista
You need to install the MySQL headers and libraries, as explained in the installation instructions. Please do read the documentation before turning to SO.
您需要安装 MySQL 头文件和库,如安装说明中所述。请在转向 SO 之前阅读文档。