在 Mac OS X 上访问 R 中的 MySQL 数据库
Access MySQL database in R on Mac OS X
我在 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
到目前为止我尝试过的:
- 我安装了 iODBC 驱动程序管理器 3.52.12。
- 我安装了 MySQL 连接器 odbc-5.3.6-osx10.11-x86-64bit 并创建了一个 DSN (server=localhost, user=root, password=*****,database=wsn_db).
我在 iODBC Administrator 中测试时遇到此错误:
[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 数据库,我建议:
- 按照this tutorial安装unixODBC和RODBC
- 安装最新的 MySQL ODBC connector. I installed mysql-connector-odbc-5.3.6-osx10.11-x86-64bit. I had to install from tar since the installer didn't work. The instructions are here。
- 我使用 ODBC Administrator 配置 DSN,但我想 [Hiltmon 的教程] 中的说明也可能有效。
我第一次使用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 驱动程序来纠正这个问题
我希望这可以为某人节省时间。
我在 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
到目前为止我尝试过的:
- 我安装了 iODBC 驱动程序管理器 3.52.12。
- 我安装了 MySQL 连接器 odbc-5.3.6-osx10.11-x86-64bit 并创建了一个 DSN (server=localhost, user=root, password=*****,database=wsn_db).
我在 iODBC Administrator 中测试时遇到此错误:
[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 数据库,我建议:
- 按照this tutorial安装unixODBC和RODBC
- 安装最新的 MySQL ODBC connector. I installed mysql-connector-odbc-5.3.6-osx10.11-x86-64bit. I had to install from tar since the installer didn't work. The instructions are here。
- 我使用 ODBC Administrator 配置 DSN,但我想 [Hiltmon 的教程] 中的说明也可能有效。
我第一次使用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 驱动程序来纠正这个问题
我希望这可以为某人节省时间。