lundi 29 juin 2015

How to Connect R to MySQL Database Using ODBC on Mac OS 10.10.3 (Yosemite)

Disclaimer upfront: I'm not a programmer, so...be gentle.

I've spent the past couple of days trying to get R studio on my Mac to connect to a MySQL database. The first hurdle faced was when running the command to install the ODBC package:

configure: error: "ODBC headers sql.h and sqlext.h not found" ERROR: configuration failed for package 'RODBC' ** Removing '/usr/lib64/R/library/RODBC'

After a lot of googling, I figured out this was solved by installing and updating something called brew, by running this command:

brew update && brew install unixODBC && \ wget "http://ift.tt/1KpD9XN" && \ R CMD INSTALL RODBC_1.3-10.tar.gz

That got RODBC installed. Now, I'm trying to connect to the database by running this syntax (as described online and in the package's documentation):

odbcConnect(dsn, uid = "", pwd = "", ...)

When I do that, I get the following error:

Warning messages: 1: In odbcDriverConnect("DSN=xyz;UID=xyz;PWD=xyz") : [RODBC] ERROR: state IM012, code 0, message [unixODBC][Driver Manager]DRIVER keyword syntax error 2: In odbcDriverConnect("DSN=xyz;UID=xyz;PWD=xyz") : ODBC connection failed

So, it seems like the syntax is wrong, but I don't see where. R documentation says that Error IM012 is a syntax error (note: replaced 'XYZ' for actual credentials) I have a few questions:

First:

On MySQL Workbench, I input the following parameters to access the database: 1. Connection Name: a made up name for the database 2. Hostname: an amazon cloud database link 3. Port (leave default of 3306) 4. Username 5. Password

Where in the RODBC syntax of odbcConnect(dsn, uid = "", pwd = "", ...) do you put the location of the database, presumably an ip or link? I tried that for the DNS, and it didn't work (i.e. got the same syntax error).

Second:

and most importantly to answer my question:

Why am I getting this IM012 syntax error? What would the correct syntax be? Where in this syntax is there room to tell the program where the database is located?

Thanks in advance for your help!

Aucun commentaire :

Enregistrer un commentaire