Saturday, October 5, 2013

RMySQL on OSX

I ran into an issue installing RMySQL on OSX. I am using a R from brew and MySQL from the Oracle download page. Trying to install RMySQL would throw up this error

Turns out that the right solution is really easy. Set your MySQL home R env var, make sure that libmysqlclient can be found by R, configure the RMySQL package with the proper inc & lib dirs for MySQL

Tests!

9 comments:

  1. Thanks! This helped me greatly.

    ReplyDelete
  2. Thank you thank you thank you!

    ReplyDelete
  3. Thank you so much for this, but on my install of R3.1, the echo home() command threw:
    [1] "/Library/Frameworks/R.framework/Resources"
    and echo "Sys.getenv('DYLD_FALLBACK_LIBRARY_PATH')" | Rscript /dev/stdin
    [1] "/Library/Frameworks/R.framework/Resources/lib"

    I am still getting the same error:
    Error : .onLoad failed in loadNamespace() for 'RMySQL', details:
    call: dyn.load(file, DLLpath = DLLpath, ...)
    error: unable to load shared object '/Users/myname/Library/R/3.1/library/RMySQL/libs/RMySQL.so':
    dlopen(/Users/myname/Library/R/3.1/library/RMySQL/libs/RMySQL.so, 6): Library not loaded: libmysqlclient.18.dylib
    Referenced from: /Users/myname/Library/R/3.1/library/RMySQL/libs/RMySQL.so
    Reason: image not found
    Error: loading failed
    Execution halted
    ERROR: loading failed

    Any ideas?

    ReplyDelete
    Replies
    1. Hi,

      I was able to get to * DONE (RMySQL) using the steps above however Library("RMySQL") failed for me giving the following error:

      Error : .onLoad failed in loadNamespace() for 'RMySQL', details:
      call: dyn.load(file, DLLpath = DLLpath, ...)
      error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RMySQL/libs/RMySQL.so':
      dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RMySQL/libs/RMySQL.so, 6): Library not loaded: libmysqlclient.18.dylib
      Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/RMySQL/libs/RMySQL.so
      Reason: image not found
      Error: package or namespace load failed for ‘RMySQL’

      I am using the R 3.1.1 GUI 1.65 Mavericks build (6784)

      HOWEVER

      library("RMySQL") works perfectly in RStudio and I am able to run all the tests above without a hitch

      hope this helps

      Delete
  4. Also want to say thank you thank you thank you!

    ReplyDelete
  5. It's caused by environment variables http://herrdu.cc/2014/12/06/R-install-RMySQL-on-Mac/

    ReplyDelete
  6. I'm getting the following error message trying to install on Yosemite:

    $ R CMD INSTALL RMySQL_0.9-3.tar.gz

    ./RS-MySQL.h:32:10: fatal error: 'mysql.h' file not found
    #include
    ^
    1 error generated.
    make: *** [RS-MySQL.o] Error 1
    ERROR: compilation failed for package ‘RMySQL’
    * removing ‘/Users/salah1/Library/R/3.1/library/RMySQL’

    ReplyDelete
    Replies
    1. You probably don't have mysql development headers in your path.

      Delete