使用unixodbc连接到数据库时出现IM004错误(macos)

时间:2018-10-06 22:44:46

标签: mysql macos rstudio unixodbc

在我的Mac上,我尝试使用unixodbc(来自Homebrew的2.3.7版)连接到数据库。

odbcinst -j显示:

DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /Users/homer/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

~/.odbc.ini/usr/local/etc/odbc.ini的部分内容:

[mysql-local]
description     = local server
Driver          = MySQLDriver
SERVER          = localhost
USER            = testuser
PASSWORD        = testpass
DATABASE        = testdb

/usr/local/etc/odbcinst.ini

的部分内容
[MySQLDriver]
Driver          = /usr/local/lib/libodbc.dylib
Setup           = /usr/local/lib/libodbc.dylib
FileUsage       = 1

驱动程序/设置文件链接到一个链接到实际驱动程序的文件:/usr/local/Cellar/unixodbc/2.3.7/lib/libodbc.2.dylib。我已将此文件的权限设置为755。

然后我尝试连接:

isql mysql-local testuser testpass -v

结果是:

[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect

由于某种原因,我有osql,Web告诉我它是用来连接到SQL Server的。 (也许它是Brew的unixodbc随附的?)我可以使用它来验证.ini文件是否已正确解析。因此

osql -I /usr/local/etc -S mysql-local -U testuser -P testpass

导致:

"" is NOT a directory, overridden by
"/usr/local/etc".
checking odbc.ini files
    reading /Users/homer/.odbc.ini
[mysql-local] found in /Users/homer/.odbc.ini
found this section:
    [mysql-local]
    description = local server
    Driver      = MySQLDriver
    Server      = 127.0.0.1
    USER        = testuser
    PASSWORD        = testpass
    DATABASE    = testdb
looking for driver for DSN [mysql-local] in /Users/homer/.odbc.ini
  found driver line: "  Driver      = MySQLDriver"
  driver "MySQLDriver" found for [mysql-local] in .odbc.ini
found driver named "MySQLDriver"
"MySQLDriver" is not an executable file
looking for entry named [MySQLDriver] in /usr/local/etc/odbcinst.ini
  found driver line: "  Driver      = /usr/local/lib/libodbc.dylib"
  found driver /usr/local/lib/libodbc.dylib for [MySQLDriver] in odbcinst.ini
/usr/local/lib/libodbc.dylib is an executable file
"Server" found, not using freetds.conf
Server is "127.0.0.1"
looking up hostname for ip address 127.0.0.1

Configuration looks OK.  Connection details:

                   DSN: mysql-local
              odbc.ini: /Users/homer/.odbc.ini
                Driver: /usr/local/lib/libodbc.dylib
       Server hostname: localhost
               Address: 127.0.0.1

Attempting connection as testuser ...
+ isql mysql-local testuser testpass -v
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
sed: /tmp/osql.dump.44362: No such file or directory

我尝试的一切总是归结为相同的错误:

[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed

出于良好的考虑,以下是isql mysql-local testuser testpass的日志:

[ODBC][54953][1538867223.117217][__handles.c][460]
        Exit:[SQL_SUCCESS]
            Environment = 0x7f9829010400
[ODBC][54953][1538867223.117416][SQLAllocHandle.c][377]
        Entry:
            Handle Type = 2
            Input Handle = 0x7f9829010400
[ODBC][54953][1538867223.117521][SQLAllocHandle.c][493]
        Exit:[SQL_SUCCESS]
            Output Handle = 0x7f982903e800
[ODBC][54953][1538867223.117601][SQLConnect.c][3721]
        Entry:
            Connection = 0x7f982903e800
            Server Name = [mysql-local][length = 11 (SQL_NTS)]
            User Name = [testuser][length = 8 (SQL_NTS)]
            Authentication = [********][length = 8 (SQL_NTS)]
        UNICODE Using encoding ASCII 'UTF-8' and UNICODE 'UCS-2-INTERNAL'

[ODBC][54953][1538867223.126854][SQLConnect.c][1380]Error: IM004
[ODBC][54953][1538867223.127046][SQLFreeHandle.c][290]
        Entry:
            Handle Type = 2
            Input Handle = 0x7f982903e800
[ODBC][54953][1538867223.127191][SQLFreeHandle.c][339]
        Exit:[SQL_SUCCESS]
[ODBC][54953][1538867223.127276][SQLFreeHandle.c][220]
        Entry:
            Handle Type = 1
            Input Handle = 0x7f9829010400

注释

    我已经在其他地方看到了相同的错误,需要由odbc中介连接到其他数据库(例如SQL Server)。在这种情况下提出的解决方案似乎不适用于MySQL连接。
  • 我希望与linuxodbc建立连接,因为据说这是R Studio IDE中实现最大SQL集成所需的工具。
  • 在Linux上,我发现unixodbc正常工作。

在此先感谢任何能向我指出正确方向的人。

0 个答案:

没有答案