MySQL 将 RMySQL 包添加到 R 失败(在 Windows 上)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4785933/
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-08-31 18:28:38  来源:igfitidea点击:

adding RMySQL package to R fails (on Windows)?

mysqlrpackagermysql

提问by Andrew

I can't figure out why my RMySQL package won't install - here's what I get:

我不知道为什么我的 RMySQL 包无法安装 - 这是我得到的:

> install.packages('RMySQL',type='source')
trying URL 'http://cran.mirrors.hoobly.com/src/contrib/RMySQL_0.7-5.tar.gz'
Content type 'application/x-gzip' length 160769 bytes (157 Kb)
opened URL
downloaded 157 Kb

* installing *source* package 'RMySQL' ...
ERROR: configuration failed for package 'RMySQL'
* removing 'C:/PROGRA~1/R/R-212~1.0/library/RMySQL'

The downloaded packages are in '(foo)'

Warning message:
In install.packages("RMySQL", type = "source") : installation of package 'RMySQL' had    non-zero exit status

I don't think it's a problem with the MySQL install, as the right values seem to be in the registry:

我不认为这是 MySQL 安装的问题,因为正确的值似乎在注册表中:

> Sys.getenv('MYSQL_HOME')
                 MYSQL_HOME "C:/PROGRA~1/MySQL/MYSQLS~1.1/" 
> readRegistry("SOFTWARE\MySQL AB", hive="HLM", maxdepth=2)
$`MySQL Server 5.1`
$`MySQL Server 5.1`$DataLocation
[1] "C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\"

$`MySQL Server 5.1`$FoundExistingDataDir 
[1] "0"

$`MySQL Server 5.1`$Location 
[1] "C:\Program Files\MySQL\MySQL Server 5.1\"

$`MySQL Server 5.1`$Version
[1] "5.1.54"

Puzzled. Any help would be greatly appreciated!

困惑。任何帮助将不胜感激!

回答by Yuriy Petrovskiy

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):

这里描述基本过程,但有几个提示,所以我将描述整个解决方案(如果需要,请更改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')并等待编译结束。

This worked for me on Windows 7 64 bit, so there should be no problems with 32 bit versions

这在 Windows 7 64 位上对我有用,所以 32 位版本应该没有问题

Initialy posted here(similar question).

最初张贴在这里(类似的问题)。

回答by Brandon Bertelsen

First I would try following the directions on this page: http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL

首先,我会尝试按照此页面上的说明进行操作:http: //biostat.mc.vanderbilt.edu/wiki/Main/RMySQL

Then, ensure that you actually have a MySQL client on your computer, not just the server itself. I've had a problem myself where I had to use an older binary for the client, but you can download these from mysql website.

然后,确保您的计算机上确实有一个 MySQL 客户端,而不仅仅是服务器本身。我自己遇到了一个问题,我不得不为客户端使用旧的二进制文件,但您可以从 mysql 网站下载这些文件。

回答by Ken Williams

I created a binary which might work for people:

我创建了一个可能对人们有用的二进制文件:

http://kenahoo.blogspot.com/2011/09/rmysql-binary-for-windows-7.html

http://kenahoo.blogspot.com/2011/09/rmysql-binary-for-windows-7.html

I basically followed all these directions, including the ones at the Vanderbilt page, but for one reason or another it doesn't always seem to work. Anyway, hope this might be helpful for people who have the same versions of stuff I used.

我基本上遵循了所有这些说明,包括范德比尔特页面上的说明,但出于某种原因,它似乎并不总是有效。无论如何,希望这可能对拥有我使用过的相同版本的东西的人有所帮助。

回答by Robbie Clarken

I was having this same problem on Windows 7 with R 2.12.1 x64 and resolved it by:

我在使用 R 2.12.1 x64 的 Windows 7 上遇到了同样的问题,并通过以下方式解决了它:

  1. Changing the R directory in my PATHvariable to C:\Program Files\R\R-2.12.1\bin\x64(rather than just ...\R-2.12.1\bin).
  2. Copying ...\MySQL Server 5.5\lib\libmysql.dllto ...\MySQL Server 5.5\bin\.
  3. Running R CMD INSTALL RMySQL_0.7-5.tar.gzin cmd.exe (install.packages('RMySQL',type='source')in R still would not work).
  1. 将我的PATH变量中的 R 目录更改为C:\Program Files\R\R-2.12.1\bin\x64(而不仅仅是...\R-2.12.1\bin)。
  2. 复制...\MySQL Server 5.5\lib\libmysql.dll...\MySQL Server 5.5\bin\.
  3. R CMD INSTALL RMySQL_0.7-5.tar.gz在 cmd.exeinstall.packages('RMySQL',type='source')中运行(在 R 中仍然不起作用)。

回答by user3262061

I came across this step-by-step guide to install RMySQL under Windows7 64bit.

我遇到了在 Windows7 64 位下安装 RMySQL 的分步指南。

http://www.ahschulz.de/2013/07/23/installing-rmysql-under-windows/

http://www.ahschulz.de/2013/07/23/installing-rmysql-under-windows/

The software I used are:

我用的软件是:

  1. Windows 8 OS
  2. R3.0.2 - 64bit
  3. Rtools 3.1
  4. MySQL Server Community Edition 5.6 - 64bit
  1. 视窗 8 操作系统
  2. R3.0.2 - 64 位
  3. 工具 3.1
  4. MySQL 服务器社区版 5.6 - 64 位

Following the above guide (with screenshots provided), my installation and loading of the RMySQL package works.

按照上述指南(提供屏幕截图),我的 RMySQL 包的安装和加载工作正常。

Many thanks to Arne Hendrik Schulz!

非常感谢 Arne Hendrik Schulz!

回答by Amos Folarin

You however there is one additional requirement at present (with the MySQL server version 5.5 & R2.12.1) follow thehttp://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL instructions at present as the locations of the libmySQL.dll differs to what is expected in the package.

然而,您目前有一个额外的要求(MySQL 服务器版本 5.5 和 R2.12.1)按照 http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL 说明目前作为 libmySQL.dll 的位置与包装中的预期不同。

i.e. for the 64bit compiling. it expects the libmySQL.dll to be in "${MYSQL_HOME}"/bin/libmySQL.dll so simply copy the dll over to the /bin dir and it will now compile.

即用于 64 位编译。它希望 libmySQL.dll 位于“${MYSQL_HOME}”/bin/libmySQL.dll 中,因此只需将 dll 复制到 /bin 目录,现在即可编译。

for the 32bit compilling. the libmySQL.lib is expected in "${MYSQL_HOME}"/lib/opt/libmysql.lib again moving this should solve the problem.

对于 32 位编译。libmySQL.lib 预计在 "${MYSQL_HOME}"/lib/opt/libmysql.lib 中再次移动这应该可以解决问题。

Alternatively, if you don't want to or can't move these files. Then you can edit the source code files: Makevars.win Makevars.win32 Makevars.win64 appropriately pointing to /lib/libmysql.dll /lib/libmysql.lib

或者,如果您不想或不能移动这些文件。然后你可以编辑源代码文件: Makevars.win Makevars.win32 Makevars.win64 适当地指向 /lib/libmysql.dll /lib/libmysql.lib

回答by Matt Bannert

As Marek said. There is no windows binary for this package. I had similar troubles on my Mac when I tried to install RPostgreSQL (because there's no binary for Mac) in the end I had to compile it on my own and modify several files.

正如马雷克所说。此软件包没有 Windows 二进制文件。当我尝试安装 RPostgreSQL 时(因为没有适用于 Mac 的二进制文件),我在 Mac 上遇到了类似的问题,最后我不得不自己编译它并修改几个文件。

For the MySQL part(if you don't know much about MySQL), you might want to use WAMPwhich is admittedly more than you need, but easy to install and to start and shut down.

对于 MySQL 部分(如果您对 MySQL 不太了解),您可能想要使用WAMP,这无疑比您需要的更多,但易于安装和启动和关闭。

For some compiling help you might be interested in Rtools

对于一些编译帮助,您可能对Rtools感兴趣

HTH

HTH

BTW: What kind of windows do you run (sry, if I missed it)

顺便说一句:你运行什么样的窗口(对不起,如果我错过了)

回答by hoelog

Add MySQL and RTools directory to the PATH!

将 MySQL 和 RTools 目录添加到 PATH!

Here is my PATH ; ~blah~;C:\Program Files\MySQL\MySQL Server 5.5\bin;c:\rtools\bin;C:\Rtools\gcc-4.6.3\bin;

这是我的路径 ; ~blah~;C:\Program Files\MySQL\MySQL Server 5.5\bin;c:\rtools\bin;C:\Rtools\gcc-4.6.3\bin;

回答by Sharad

I was working for last 2 days on Installation of R with RMySQL package, finally got the solution for that, here are the steps to install RMySQL package:-

我过去 2 天一直在用 RMySQL 包安装 R,终于找到了解决方案,以下是安装 RMySQL 包的步骤:-

  1. DOWNLOAD SOFTWARE FROM THE FOLLOWING LINKS: *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*
    
  2. SET THE FOLLOWING ENVIRONMENT VARIABLES

     * 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. *
    

    Be sure that the following paths areincluded in your Windows PATH variable: \Rtools\2.14\bin \Rtools\2.14\MinGW\bin \Rtools\2.14\MinGW64\bin

  3. CREATE FOLDER AND COPY FILES

    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 \\R\R-2.14.0\bin\ (64 bit) Or \\R\R-2.14.0\bin\i386\ (32 bit) and to C:\Windows\System32.

  1. 从以下链接下载软件:*a。R2.13.2:从http://cran.stat.sfu.ca/index.html下载 R

      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*
    
  2. 设置以下环境变量

     * 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

  3. 创建文件夹和复制文件

    一种。OPT:在C:\Program Files\MySQL\MySQL Server 5.5\lib下创建一个文件夹OPT,将
    MYSQLLIB.LIB复制到上面的路径。同时将 libmysql.dll 复制到 \\R\R-2.14.0\bin\(64 位)或 \\R\R-2.14.0\bin\i386\(32 位)并复制到 C:\Windows\System32。

b. Renviron.site: create or edit a file \\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

湾 Renviron.site:创建或编辑文件 \\R\R-2.14.0\etc\Renviron.site 并添加一行:MYSQL_HOME =”C:/Program Files/MySQL/MySQL Server 5.5/” 注意:使用 FORWARD SLASH和双引号在这里

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

C。libMySQL.dll:将此文件复制到 C:\Program Files\R\R-2.13.2\bin\i386 以及 C:\Program Files\R\R-2.13.2\bin

  1. RUN COMMANDS

    a. Install.Packages: Run R GUI by clicking on the R icon on desktop or from Start menu. Type INSTALL.PACKAGES(“RMySQL”,type=”Sources”). This will download the required software from repositories.

  1. 运行命令

    一种。Install.Packages:通过单击桌面上的 R 图标或从开始菜单运行 R GUI。输入 INSTALL.PACKAGES(“RMySQL”,type=”Sources”)。这将从存储库下载所需的软件。

b. Command Prompt: Copy the downloaded zip file (in step 4.a.) and paste it under R installation folder. Go to start menu and open Command Prompt. Go to the R installation folder and type R CMD INSTALL RMySQL_0.8-0.tar.gz

湾 命令提示符:复制下载的 zip 文件(在步骤 4.a. 中)并将其粘贴到 R 安装文件夹下。转到开始菜单并打开命令提示符。转到 R 安装文件夹并键入 R CMD INSTALL RMySQL_0.8-0.tar.gz

  *COMMANDS:
  >library(RMySQL)
   >drv = dbDriver("MySQL")
   >con = dbConnect(drv,host="localhost",dbname="test",user="root",pass="root")
   >album = dbGetQuery(con,statement="select * from t_master")
   >album*

回答by Andrew

18 months later, new laptop, same problem. Returning to the scene of the crime - sorry January 2011 self; we're in the future, and this installation still isn't any fun.

18 个月后,新笔记本电脑,同样的问题。回到案发现场——对不起2011年1月的自己;我们在未来,这个安装仍然没有任何乐趣。

Lessons learned:

得到教训:

-Updated RTools are essential. Get them.

- 更新的 RTools 是必不可少的。得到他们

-Are you seeing an error along the lines of .onLoad failed in loadNamespace() for 'RMySQL', details? This seems to mean that there's a problem with your system environment variables.

- 您是否看到类似的错误.onLoad failed in loadNamespace() for 'RMySQL', details?这似乎意味着您的系统环境变量存在问题。

In R, run

在 R 中,运行

Sys.getenv('MYSQL_HOME')

If it spits back a path like

如果它吐出一条像

 [1] "C:\Program Files\MySQL\MySQL Server 5.6"

you're good. But if it gives you empty string, you need to set this.

你很厉害。但是如果它给你空字符串,你需要设置它。

These are all Windows 7 directions, but the process is pretty similar in XP, if memory serves.

这些都是 Windows 7 的方向,但如果没记错的话,这个过程在 XP 中非常相似。

1) Bring up System Properties > Advanced > Environment Variables.

1) 调出系统属性 > 高级 > 环境变量。

2) In the lower 'System Variables' pane, click 'New'.

2) 在下方的“系统变量”窗格中,单击“新建”。

3) Variable name is MYSQL_HOMEand value is whatever the path is to your MySQL installation - mine was C:\Program Files\MySQL\MySQL Server 5.6

3)变量名是MYSQL_HOME,值是你的MySQL安装路径 - 我的是C:\Program Files\MySQL\MySQL Server 5.6

Newer versions of MySQL don't seem to create an environment variable on install - that and the lack of binaries for RMySQL explain why this questions has garnered 8,000 hits.

较新版本的 MySQL 似乎没有在安装时创建环境变量 - 这和缺少 RMySQL 二进制文件解释了为什么这个问题已经获得了 8,000 次点击。

-Still stuck? Here are two additional in-depth writeups: 1, 2

- 还卡住了吗?这里有两个附加的深入writeups:12