在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:21:30  来源:igfitidea点击:

Using MySQL in R for Windows

mysqlwindowsr

提问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版本和路径)

  1. Install latest RTools from here
  2. install MySQL or header and library files of mysql
  3. create or edit file C:\Program Files\R\R-2.12.1\etc\Renviron.siteand add line like MYSQL_HOME=C:/mysql(path to your mysql files)
  4. copy libmysql.lib from mysql/lib to mysql/lib/opt to meet dependencies.
  5. copy libmysql.dll to C:\Program Files\R\R-2.12.1\binor to windows/system32directory.
  6. run install.packages('RMySQL',type='source')and wait while compilation will end.
  1. 这里安装最新的 RTools
  2. 安装 MySQL 或 mysql 的头文件和库文件
  3. 创建或编辑文件C:\Program Files\R\R-2.12.1\etc\Renviron.site并添加类似行MYSQL_HOME=C:/mysql(mysql 文件的路径)
  4. 将 libmysql.lib 从 mysql/lib 复制到 mysql/lib/opt 以满足依赖项。
  5. 将 libmysql.dll 复制到C:\Program Files\R\R-2.12.1\binwindows/system32目录。
  6. 运行install.packages('RMySQL',type='source')并等待编译结束。

Thanks to all who tried to answer.

感谢所有试图回答的人。

回答by Matt Bannert

possible duplicate. However, my suggestions is to try WAMP which comes as a one click install. Admittedly you get more than you need (webserver) but the MySQL installation runs pretty well.

可能重复。但是,我的建议是尝试一键安装的 WAMP。诚然,你得到的比你需要的多(网络服务器),但 MySQL 安装运行得很好。

回答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 之前阅读文档。