如何将R与MySQL连接或如何安装RMySQL软件包? [英] How to Connect R with MySQL or how to install RMySQL package?

查看:211
本文介绍了如何将R与MySQL连接或如何安装RMySQL软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R的新手,我正在尝试将R与MySQL连接.我已经为64位安装了mysql-5.5.22-winx64R-2.12.0.我已经设置了MYSQL_HOME environment path(C:\Program Files\MySQL\MySQL Server 5.5)并尝试执行以下步骤:

I am new in R and i am trying to connect R with MySQL. I have installed mysql-5.5.22-winx64 and R-2.12.0 for 64 bit. I have already set MYSQL_HOME environment path(C:\Program Files\MySQL\MySQL Server 5.5) and trying to follow these steps:

  1. 从此处安装最新的RTools
  2. 安装MySQL或mysql的头文件和库文件
  3. 创建或编辑文件C:\Program Files\R\R-2.12.1\etc\Renviron.site并添加MYSQL_HOME=C:/mysql之类的行(您的mysql文件的路径)
  4. libmysql.libmysql/lib复制到mysql/lib/opt以满足依赖关系.
  5. libmysql.dll复制到C:\Program Files\R\R-2.12.1\binwindows/system32 directory.
  6. 运行install.packages('RMySQL',type='source')并等待编译结束. 但仍然出现此错误:-

  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.site and 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\bin or to windows/system32 directory.
  6. run install.packages('RMySQL',type='source') and wait while compilation will end. but still i am getting this error:-

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

请建议我如何解决此问题?

Please suggest me how can I solve this problem?

最后我得到了解决方案: 您可以在我的博客.

Finally I got the solution:- You can see the solution in detail on my blog.

我花了两天时间用RMySQL软件包安装R,最终找到了解决方案,以下是安装RMySQL软件包的步骤:-

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

  1. 通过以下链接下载软件:

  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*

  • 设置以下环境变量

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

    确保Windows PATH变量中包含以下路径: \ Rtools \ 2.14 \ bin \ Rtools \ 2.14 \ MinGW \ bin \ Rtools \ 2.14 \ MinGW64 \ bin

    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

    创建文件夹和副本文件

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

    1. 运行命令

    1. RUN COMMANDS

    a. Install.Packages:通过单击桌面上的R图标或从开始"菜单运行R GUI.类型 INSTALL.PACKAGES("RMySQL",type ="Sources"). 这将从存储库中下载所需的软件.

    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.

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

    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

    *命令:

    库(RMySQL) drv = dbDriver("MySQL") con = dbConnect(drv,host ="localhost",dbname ="test",user ="root",pass ="root") 专辑= dbGetQuery(con,statement ="select * from t_master") 相册*

    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*

  • 推荐答案

    这不是直接的答案,但您仍然会发现有帮助:

    It is not a direct answer but still you may find it helpful:

    1. 使用R的最新版本(当前为2.15)

    1. Use a more up to date version of R (currently at 2.15)

    在Windows平台上,我宁愿使用RODBC + Windows MySQL驱动程序,除非您处于具有异构平台(即Linux和Windows)的环境中,在该环境中团队成员之间大量共享代码.即使然后根据运行的平台在同一脚本中使用RMySQL和RODBC之间进行选择,也是一个简单的if() {...} else {...}

    On Windows platforms I'd rather use RODBC + Windows MySQL driver, unless you are in a environment with heterogenous platforms (i.e. Linux and Windows) where code is heavily shared among team members. And even then choosing between using RMySQL and RODBC in the same script depending on the platform it runs is a simple if() {...} else {...}

    请注意,我并不是说您尝试做的事没有成功的故事,但是恕我直言,通过上述操作,您会早日投入运营.

    Notice that I am not saying there are no success stories with what you are trying to do, but IMHO you'll be up and running sooner with the above.

    这篇关于如何将R与MySQL连接或如何安装RMySQL软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆