mysql - 在 Mac OS X 上使用 R 访问 MySQL 数据库

标签 mysql r macos rodbc

我在 mac (Mac OS X 10.11.2) 上从 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(服务器 = localhost,用户 = root,密码 =*****,数据库 = 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 位的问题。

  • 所以我安装了 MySQL 连接器 odbc-5.2.7-osx10.7-x86-32bit,这是我找到的最新 32 位版本。当我使用 iODBC Administrator 对此进行测试时,它似乎可以工作,但是当我在 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.

  • 所以我检查了权限,但它们是正确的。
  • 我还重新安装了驱动程序,但没有任何改变。

  • 阅读后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
    

    但这似乎并没有改变任何事情。

  • 我还尝试了基于 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 数据也会有所帮助。

    最佳答案

    我终于设法通过使用 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 教程] 中的说明也可能有效。
    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
      

      我按照 RODBC error - ODBC connection failed - can't connect to MySQL with my mac (mavericks) 中的建议选择 ANSI 驱动程序来纠正此问题.

    我希望这可以为某人节省时间。

    关于mysql - 在 Mac OS X 上使用 R 访问 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39751700/

    相关文章:

    c++ - 在 C++ 中,如何在 MacOS X 中将程序与 libpng/zlib/loadpng 链接?

    r - 使用 rjags 定义条件线性高斯网络

    objective-c - 在 OS X 上读取登录用户的域

    macos - 如何使用 applescript 按应用程序顺序枚举正在运行/打开的应用程序?

    java - NetBeans MySQL 驱动程序连接错误 dist Jar 文件

    regex - 如何设置正则表达式以在 R 中使用 grep 或 dplyr 查找变量?

    r - ggfortify::autoplot 或 ggfortify::::autoplot 不工作

    php - 更新查询不起作用并将字段更改为 0

    MySQL选择特定数量并计算所有可能

    php - 这个查询有什么问题?