Using MySQL in R for Windows
Asked Answered
C

3

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?

Choreograph answered 7/3, 2011 at 17:41 Comment(3)
Are you using 32/64-bit R with a 64/32-bit MySQL? That could break things.Genovese
@RichieCotton Windows 7 x64 R and MySQL -32 bit. Unable to install package.Choreograph
@RichieCotton MySQL runs fine and several programs connects to it successfully. Everything except windows is 32 bit. The problem is with installing this package. I just do not know there to start.Choreograph
C
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.

Choreograph answered 8/3, 2011 at 10:9 Comment(2)
Thanks for posting your own solution here, I'm sure it will be helpful to other people who might have a similar problem.Nab
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?Dorella
B
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.

Bertiebertila answered 7/3, 2011 at 22:56 Comment(1)
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.Choreograph
N
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.

Nab answered 7/3, 2011 at 18:16 Comment(3)
have you succeeded? What compiler should be used? Should I install MS Visual studio (what version?), mingw or some other compiler? No answers there.Choreograph
@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 and then installed RMySQL with install.packages("RMySQL", type="source").Nab
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 :(Choreograph

© 2022 - 2024 — McMap. All rights reserved.