14

How to use MySQL in R (statistic language) for Windows (7)?

There is no problems then using linux:

install.packages('RMySQL')
library(RMySQL)
...

But I found no such package for Windows on CRAN. There is only note about this fact. I found package for version 2.10, but it is not usable in 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?

Yuriy Petrovskiy
  • 7,888
  • 10
  • 30
  • 34

3 Answers3

14

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

  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.

Thanks to all who tried to answer.

Community
  • 1
  • 1
Yuriy Petrovskiy
  • 7,888
  • 10
  • 30
  • 34
  • Thanks for posting your own solution here, I'm sure it will be helpful to other people who might have a similar problem. – Ista Mar 08 '11 at 17:16
  • 1
    Hi, I am trying to follow these instructions. I find my MySQL installed in `C:/Program Files (x86)/MySQL`, so I made the content as `**MYSQL_HOME="C:/Program Files (x86)/MySQL"**`. But coming to the 4th step, I find the `libmysql.lib` file in `lib` folder all right, but I can't find any `opt` folder in `lib`. What should I do now? – SexyBeast Jun 05 '13 at 13:53
1

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.

Community
  • 1
  • 1
Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
  • There are no issues about mysql server. Thanks for link. I have followed it and found a solution. It is not so straightforward so I had described in separate answer. Thank you for help. – Yuriy Petrovskiy Mar 08 '11 at 10:12
0

You need to install the MySQL headers and libraries, as explained in the installation instructions. Please do read the documentation before turning to SO.

Ista
  • 10,139
  • 2
  • 37
  • 38
  • have you succeeded? What compiler should be used? Should I install MS Visual studio (what version?), mingw or some other compiler? No answers there. – Yuriy Petrovskiy Mar 07 '11 at 18:29
  • @Yuriy unfortunately I can't install software on my work computer so I can't really test it out. It has been awhile since I've done this on Windows, but I don't remember it being terribly difficult. I think I just installed MySQL (from [mysql.com](http://mysql.com) and then installed RMySQL with `install.packages("RMySQL", type="source")`. – Ista Mar 07 '11 at 19:06
  • tried this: `R CMD INSTALL --configure-args="--with-mysql-dir=C:\mysql" -l ".../R/win-library/2.12" RMySQL_0.7-5.tar.gz` and failed with same errors :( – Yuriy Petrovskiy Mar 07 '11 at 19:49