title: How to Connect R with MySQL or how to install RMySQL package?
body: <p>I am new in R and i am trying to connect R with MySQL. I have installed <code>mysql-5.5.22-winx64</code> and <code>R-2.12.0</code> for 64 bit. I have already set <code>MYSQL_HOME environment path(C:\Program Files\MySQL\MySQL Server 5.5)</code> and trying to follow these steps:</p>
  
  <ol>
  <li>Install latest RTools from here  </li>
  <li>install MySQL or header and library files of mysql  </li>
  <li>create or edit file <code>C:\Program Files\R\R-2.12.1\etc\Renviron.site</code> and add line like <code>MYSQL_HOME=C:/mysql</code> (path to your mysql files)  </li>
  <li>copy <code>libmysql.lib</code> from <code>mysql/lib</code> to <code>mysql/lib/opt</code> to meet dependencies.  </li>
  <li>copy <code>libmysql.dll</code> to <code>C:\Program Files\R\R-2.12.1\bin</code> or to <code>windows/system32 directory</code>.  </li>
  <li><p>run <code>install.packages('RMySQL',type='source')</code> and wait while compilation will end.
  but still i am getting this error:-</p>
  
  <pre><code>*&gt; 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*
  </code></pre></li>
  </ol>
  
  <p>Please suggest me how can I solve this problem?</p>
  
  <p>Finally I got the solution:-
  You can see the solution in detail on my <a href="http://passionfordata.blogspot.in/2012/04/how-to-install-r-and-rmysql-package.html" rel="noreferrer">blog</a>.</p>
  
  <p>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:-</p>
  
  <ol>
  <li><p>DOWNLOAD SOFTWARE FROM THE FOLLOWING LINKS:</p>
  
  <pre><code>   * 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*
  </code></pre></li>
  <li><p>SET THE FOLLOWING ENVIRONMENT VARIABLES</p>
  
  <pre><code>    * a. MYSQL_HOME : &lt;drive&gt;/path to MySQL installation folder
           e.g. MYSQL_HOME= C:\Program Files\MySQL\MySQL Server 5.5\  
  
        b. R_HOME: &lt;drive&gt;/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. *
  </code></pre>
  
  <p>Be sure that the   following paths areincluded in your Windows PATH variable:
           <em>\Rtools\2.14\bin
            \Rtools\2.14\MinGW\bin
            \Rtools\2.14\MinGW64\bin</em></p></li>
  <li><p>CREATE FOLDER AND COPY FILES</p>
  
  <pre><code>    * 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
                &lt;drive&gt;\&lt;path&gt;\R\R-2.14.0\bin\(64 bit) Or
                &lt;Drive&gt;\&lt;path&gt;\R\R-2.14.0\bin\i386\ (32 bit) and
           to C:\Windows\System32.
  
        b. Renviron.site: create or edit a file 
                &lt;DRIVE&gt;\&lt;path&gt;\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*
  </code></pre>
  
  <ol>
  <li><p>RUN COMMANDS</p>
  
  <p>a. Install.Packages: Run R GUI by clicking on the R icon on desktop or from  Start menu. Type 
           <em>INSTALL.PACKAGES(“RMySQL”,type=”Sources”).</em>
       This will download the required software from repositories.</p>
  
  <p>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</p>
  
  <p>*COMMANDS:</p>
  
  <blockquote>
    <p>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*</p>
  </blockquote></li>
  </ol></li>
  </ol>