2016-09-28 55 views
0

我在Mac上從R(Mac OS X 10.11.2)訪問我的MySQL數據庫時遇到問題。下面的代碼:在Mac OS X上訪問R中的MySQL數據庫

library("RODBC") 
mycom <- odbcConnect("wsn_mysql_5", uid="root", pwd="*****") 

給出了這樣的錯誤:

1: In RODBC::odbcDriverConnect("DSN=wsn_mysql_5;UID=root;PWD=****") : 
[RODBC] ERROR: state 00000, code 15509574, message 
[iODBC][DriverManager]dlopen(/usr/local/lib/libmyodbc5a.so, 
6): no suitable image found. Did find: 
/usr/local/lib/libmyodbc5a.so: mach-o, but wrong architecture 
2: In RODBC::odbcDriverConnect("DSN=wsn_mysql_5;UID=root;PWD=****") : 
[RODBC] ERROR: state IM003, code 15509574, message 
[iODBC][Driver Manager]Specified driver could not be loaded 

我迄今爲止嘗試:

  1. 我安裝的iODBC驅動程序管理器3.52.12。
  2. 我安裝了MySQL連接器odbc-5.3.6-osx10.11-x86-64bit並創建了一個DSN(server = localhost,user = root,password = *****,database = wsn_db)。

在iODBC的管理員測試時我得到這個錯誤:

[iODBC][Driver manager]dlopen(/usr/local/lib/libmyodbc5w.so, 6): no suitable image found. 
Did find: /usr/local/lib/libmyodbc5w.so: mach -o, but wrong architecture. 

How to add ODBC to MAMP on OSX使我認爲,這是是一個32位和64位的問題。

  1. 所以我安裝了MySQL連接器odbc-5.2.7-osx10.7-x86-32bit這是我發現的最新的32位版本。當我測試這與iODBC的管理員,它似乎工作,但我會在開頭提到的錯誤,當我嘗試在R.

的iODBC的常見問題解答說,關於代碼這種類型的錯誤如下:

[iODBC] [Driver Manager]Specified driver could not be loaded

There are a few reasons why this could occur, and thinking through the architecture helps. Your application has loaded libiodbc successfully, and it has found an odbc.ini file (or equivalent through the ODBCINI environment variable), and it has found a DSN within that odbc.ini that matches the name requested in your connection.

However, the driver manager has had problems loading the library specified in the `Driver=' line of that DSN definition. Either it doesn't exist, or its permissions are insufficient to allow your application to load it (it must be readable and executable, and the directories leading down to it must be executable), or maybe the file is not a dynamic library - it could be a static library (a *.a file except on AIX) or is otherwise corrupted. These are all things to check, or you may be best off reinstalling the driver if all the permissions check out.

  1. 所以我檢查了權限,但他們是正確的。
  2. 我也重新安裝了驅動程序,但它沒有改變任何東西。

  3. 看完this後,我檢查了odbc.ini和obdcinst.ini。

我改變的odbc.ini到:

[ODBC Data Sources] 
wsn_mysql_7 = wsn_mysql_7 

[ODBC] 
TraceLibrary= 

[wsn_mysql_7] 
Driver = /usr/local/lib/libmyodbc5w.so 
DATABASE = wsn_db 
DESCRIPTION = DSN for wsn_db in R 
SERVER = localhost 
UID = root 
PASSWORD = ***** 

和ODBCINST.INI到

[ODBC Drivers] 
MySQL ODBC 5.2 ANSI Driver=Installed 
MySQL ODBC 5.2 Unicode Driver=Installed 

[ODBC Connection Pooling] 
PerfMon=0 
Retry Wait= 

[MySQL ODBC 5.2 ANSI Driver] 
Driver = /usr/local/lib/libmyodbc5a.so 
Description = mySQL driver 
Threading = 0 

[MySQL ODBC 5.2 Unicode Driver] 
Driver = /usr/local/lib/libmyodbc5w.so 
Description = mySQL driver 
Threading = 0 

但它似乎沒有任何改變。

  1. 我也嘗試了一種基於this question的替代RODBC代碼。

    mycom <- odbcDriverConnect("Provider=MSDASQL;Driver={MySQL ODBC 5.2 UNICODE Driver}; 
    Server=localhost;database=wsn_db;Uid=root;Pwd=*****;Option=3") 
    

我不知道下一步該怎麼做?即使是以完全不同的方式訪問R中的mySQL數據也會有所幫助。

+2

你試過[RMySQL](https://cran.r-project.org/package=RMySQL)嗎? – ytk

+0

我已經成功(最終)與RMYSQL在MAMP的Mac上 –

+0

RMySQL是否需要一個ODCB驅動程序?因爲我認爲這是問題的來源。 –

回答

1

我最終設法通過使用unixODBC和使用64位ANSI連接器來進行工作配置。如果你想與RODBC連接到MySQL數據庫,我建議:

  1. 要遵循this tutorial安裝了unixODBC和RODBC
  2. 安裝最新MySQL ODBC connector。我安裝了mysql-connector-odbc-5.3.6-osx10.11-x86-64bit。由於安裝程序不工作,我必須從tar安裝。說明是here
  3. 我使用ODBC管理器來配置DSN,但我猜[Hiltmon's tutorial]的指令可能也適用。
  4. 我第一次使用Unicode的驅動程序,但得到了以下錯誤:

    Warning messages: 
    1: In RODBC::odbcDriverConnect("DSN=wsn_db_dsn;UID=root;PWD=****") :  
    [RODBC] ERROR: state H, code 0, message [unixODBC][ 
    2: In RODBC::odbcDriverConnect("DSN=wsn_db_dsn;UID=root;PWD=****") : 
    ODBC connection failed 
    

    我通過選擇ANSI驅動器作爲RODBC error - ODBC connection failed - can't connect to MySQL with my mac (mavericks)建議糾正這一點。

我希望這可以節省時間給別人。