5

On my Mac I'm trying to connect to databases with unixodbc (v. 2.3.7 from Homebrew).

odbcinst -j shows:

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

Partial contents of ~/.odbc.ini and /usr/local/etc/odbc.ini:

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

Partial contents of /usr/local/etc/odbcinst.ini

[MySQLDriver]
Driver          = /usr/local/lib/libodbc.dylib
Setup           = /usr/local/lib/libodbc.dylib
FileUsage       = 1

The Driver/Setup file links to a file that links to actual driver: /usr/local/Cellar/unixodbc/2.3.7/lib/libodbc.2.dylib. I have set the perms on this file to 755.

Then I try to connect:

isql mysql-local testuser testpass -v

The result is:

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

For some reason I have osql, which the Web tells me is used to connect to SQL Server. (Perhaps it comes with the Brew's unixodbc?) I can use it to verify that the .ini files are being parsed correctly. Thus

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

results in:

"" 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

Everything I try always comes down to the same error:

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

For good measure, here are the logs from 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

Notes:

  • I have seen the same error discussed elsewhere, where odbc-mediated connections to other databases (e.g., SQL Server) are desired. Solutions proposed in those cases do not appear to apply to MySQL connections.
  • I am hoping to make the connections this with linuxodbc, as this is the instrument said to be required for maximum SQLintegration in the R Studio IDE.
  • On Linux I find that unixodbc works fine.

Much thanks in advance to anyone who can point me in the right direction.

Homer White
  • 733
  • 1
  • 5
  • 14

0 Answers0