问题
I am trying to connect to a mysql database through R using RODBC on my mac (mavericks) but after a stupid number of hours of effort, I still can't get it working. When I try to connect to a database, RODBC throws this error (error message is so terse, I don't know what it means):
ch <- odbcConnect("mydatabasename") "Warning messages: 1: In odbcDriverConnect("DSN=mydatabase") : [RODBC] ERROR: state H, code 0, message [unixODBC][ 2: In odbcDriverConnect("DSN=mydatabasename") : ODBC connection failed"
I got to where I am at by following the instructions at the following blog (install unixODBC): http://hiltmon.com/blog/2013/09/18/setup-odbc-for-r-on-os-x/
It shows me that I am connected, if I enter:
isql -v mydatabasename
I installed R from source and the install worked with no noticeable errors, but now when I try to connect to a database from Rstudio, with:
ch <- odbcConnect("mydatabasename")
I get the ODBC connection failed error. Can anyone help me understand what this error means? Or how I could potentially fix it? Or who I can talk with to get some help?
You would keep me from shooting myself. haha! But seriously... you would.
回答1:
I had exactly the same problem as you've reported. My ODBC connection was using the MySQL ODBC 5.3 Unicode Driver (/usr/local/lib/libmyodbc5w.so) Although I could connect with iSQL, actual SQL commands were returning garbage.
I tried changing my odbc.ini to use the the ANSI driver instead (/usr/local/lib/libmyodbc5a.so). It worked and now RODBC can connect to my MySQL database.
来源:https://stackoverflow.com/questions/24461322/rodbc-error-odbc-connection-failed-cant-connect-to-mysql-with-my-mac-maver