RMySQL

RMySQL is a package to interact with MySQL databases from R.

Installing RMySQL on Windows

VERY quick-and-dirty, to be cleaned-up.

This should work on both 32 and 64 bit versions of R.

Most of the steps are performed through Windows command line interface. While perhaps it is not necessary, I find it convenient and also easier to explain.

This assumes you have R already installed.

Crucial steps at a glance:

  1. Install appropriate version of Rtools from http://www.murdoch-sutherland.com/Rtools/.
  2. Download and install MySQL Connector / C from http://dev.mysql.com/downloads.
  3. Setup R environment so that it sets MYSQL_HOME variable
  4. Install RMySQL from R using install.packages.

Detailed instructions follows.

Install Rtools

Rtools is a collection of compilers and various tools necessary to build R packages and R itself from sources on Windows. Download the appropriate version (for your R version) from http://www.murdoch-sutherland.com/Rtools/. It is a Windows Installer. Launch it and install it. The requirement is that the path to where it is going to be installed should not contain spaces. Obviously the default location C:\Rtools is OK.

We will assume that it is installed to C:\programs\Rtools.

Install MySQL Connector / C

Download it from here http://dev.mysql.com/downloads. There are multiple versions available. Download either the 32 or 64 bit version depending on your system. It is enough to get the ZIPped version, not the MSI installer. So, for example mysql-connector-c-noinstall-6.0.2-winx64.zip for the 64 bit version.

Download it and unzip recreating the directories contained within the zip to some place where, again, the path does not contain spaces. We put it, say, to C:\programs. As the unpacking will create a direcory with a loooong name mysql-connnector-noinstall.. rename it to something shorter, for example just mysql-connector.

In the end we have a folder C:\programs\mysql-connector that has the subfolders bin, include etc. and some other files.

Environment

Now comes the tricky part.

This assumes that R is installed to c:\program files\R\2.12-0.

Open notepad and put the following there

set path=%path%;c:\program files\R\2.12-0\bin\x64;c:\programs\Rtools\bin;c:\programs\rtools\mingw64\bin;c:\programs\mysql-connector\bin;c:\programs\mysql-connector\lib;c:\programs\mysql-connector\include

Save this file in, for example, c:\programs.

Open the Windows command line. Shortcut is in the Menu Start | Applications. Alternatively, just use “Run…” and type cmd and hit Enter. Navigate to c:\programs with

cd /d c:\programs

Launch the file by just typing its name.

Check if everything is OK.

Launch R in the command line by just typing R.

Sys.getenv("MYSQL_HOME")
# should give the location of mysql-connector

Install RMySQL

install.packages("RMySQL", type="source")