How to deal with MySQL Connector/ODBC error "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'"

Posted by user12653020 on Oracle Blogs See other posts from Oracle Blogs or by user12653020
Published on Wed, 30 Oct 2013 08:31:44 +0000 Indexed on 2013/10/30 10:07 UTC
Read the original article Hit count: 216

Filed under:
I am sure many users run into a mysterious problem when perfectly working ODBC configurations started failing with errors like:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
The above error message might be preceded with something like [nxDc[yQ]. At the same time odbc.ini specifies in its DSN different SOCKET=/tmp/mysql.sock or a TCP connection SERVER=<remote_host_or_ip>. The question is, what had happened that the ODBC driver started to ignore the DSN options? The clue lies in the corrupted string [nxDc[yQ], which actually was [UnixODBC][MySQL] with each 2nd symbol removed. This is the case of bad conversion from SQLCHAR to SQLWCHAR. The UnixODBC driver manager took a single-byte character string from the client application and tried to convert it into the wide (multi-byte) characters for the Unicode version of MyODBC driver: Initially the piece of the connection string was represented by 1-byte chars like:
[S][E][R][V][E][R][=][m][y][h][o][s][t][;]
after the bad conversion to wide chars (commonly 2-byte UTF-16)
[SE][RV][ER][=m][yh][os][t;]
instead of
[S\0][E\0][R\0][V\0][E\0][R\0][=\0][m\0][y\0][h\0][o\0][s\0][t\0][;\0]
Naturally, the MyODBC driver could not parse the bad string and tried to use the default connection type (SOCKET) with the default value (/var/lib/mysql/mysql.sock) Now we know what happened, but why it happened? In most cases it happened because of using ODBCManageDataSourcesQ4 utility or its older analog ODBCConfig. When registering ODBC drivers they put lots of additional options and one of these options badly affects the UnixODBC driver manager itself. The solution is simple - remove or comment out the option in odbcinst.ini file (it is empty by default) set for the driver:
[MySQL ODBC 5.2.6 Driver]
Description    =
Driver         = /home/dbs/myodbc526/lib/libmyodbc5w.so
Driver64       = /home/dbs/myodbc526/lib/libmyodbc5w.so
Setup          = /home/dbs/myodbc526/lib/libmyodbc5S.so
Setup64        = /home/dbs/myodbc526/lib/libmyodbc5S.so
UsageCount     = 1
CPTimeout      = 0
CPTimeToLive   = 0
IconvEncoding  =  # <--------- remove this line
Trace          =
TraceFile      =
TraceLibrary   =
After applying this simple solution (remove the line with IconvEncoding = ) everything came to normal. Prior to removing that line I tried putting different encoding names there, but the result was not good, so I really don't know how to properly use it. Unfortunately, UnixODBC manuals say nothing about it. Therefore, removing this option was the only way to get things done.

© Oracle Blogs or respective owner

Related posts about /Oracle