I have an Amazon linux instance on which i have installed a server named ejabberd
Inside it I have a code written in erlang as (db.erl).
-module(db).
-export([connection/0]).
connection()->
odbc:start(),
ConnectionString = "DSN=qaz;UID=root;PWD=abc",
{ok, Ref} = odbc:connect(ConnectionString, []),
Ref.
But when I this code is about to run I get an error as
[error] gen_server myapp terminated with reason: no match of right hand
value {error,"[unixODBC][Driver Manager]Can't open lib
'/usr/lib/libmyodbc5.so' : file not found SQLSTATE IS: 01000 Connection to
database failed."} in db:connection/0 line 15
10:34:15.111 [error] CRASH REPORT Process myapp with 0 neighbours exited
with reason: no match of right hand value {error,"[unixODBC][Driver
Manager]Can't open lib '/usr/lib/libmyodbc5.so' : file not found SQLSTATE
IS: 01000 Connection to database failed."} in db:connection/0 line 15 in
gen_server:terminate/7 line 812
10:34:15.111 [error] Supervisor frequency_sup had child myapp started with
myapp:start() at <0.502.0> exit with reason no match of right hand value
{error,"[unixODBC][Driver Manager]Can't open lib '/usr/lib/libmyodbc5.so' :
file not found SQLSTATE IS: 01000 Connection to database failed."} in
db:connection/0 line 15 in context child_terminated
I have edited my /etc/odbc.ini and /root/.odbc.ini with following configurations
[ODBC Data Sources]
qaz= ODBC for MySQL
[qaz]
Driver = /usr/lib64/libmyodbc5.so
Description = ODBC for MySQL
SERVER = localhost
PORT = 3306
USER = root
Password = abc
Database = mydb
and my odbcinst.ini file looks like this
# Example driver definitions
# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
[MySQL ODBC 5.3 Unicode Driver]
Driver = /usr/lib/libmyodbc5w.so
UsageCount = 1
[MySQL ODBC 5.3 ANSI Driver]
Driver = /usr/lib/libmyodbc5a.so
UsageCount = 1
And when I run command
isql qaz [root [abc]]
I get an error as
[ISQL]ERROR: Could not SQLConnect
Can Anyone tell me the issue and guide me with the correct way to set up odbc configurations in linux
I have done it successfully on windows though, but I am not too familiar with linux.
Thank you in advance
It's the ODBC driver (ODBC Connector) that is provided by mySQL. Did you pre-install the driver? Search how to install mysql odbc driver.
However, I would recommend using another mysql driver, like mysql/otp and not ODBC driver. I've had problems using the ODBC driver with mySql.
Related
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.
I need to connect my HANA Express VM with a MySQL database. What I did so far is:
0.) Registered VM and installed unixODBC (as described in Youtube Playlist)
1.) Downloaded ODBC driver installation files (rpm)
2.) sudo zypper install
3.) myodbc-installer -d -l
4.) cp /etc/unixODBC/odbc.ini ~/.odbc.ini
5.) cp /etc/unixODBC/odbcinst.ini ~/.odbcinst.ini
6.) nano ~/.odbc.ini
[ODBC Data Sources]
ds2 = myodbc5w
ds1 = myodbc5a
Default = Default
[myodbc5w]
Driver = /usr/lib64/libmyodbc5w.so
DATABASE = <sqldb>
DESCRIPTION = MySQL ODBC 5.3 Unicode Driver test
SERVER = <sqlip>
UID = <sqluser>
USER = <sqluser>
PASSWORD = <pw>
[myodbc5a]
Driver = /usr/lib64/libmyodbc5a.so
DATABASE = <sqldb>
DESCRIPTION = MySQL ODBC 5.3 ANSI Driver test
SERVER = <sqlip>
UID = <sqluser>
USER = <sqluser>
PASSWORD = <pw>
[Default]
Driver = /usr/lib64/libmyodbc5a.so
DATABASE = <sqldb>
DESCRIPTION = MySQL ODBC 5.3 ANSI Driver test
SERVER = <sqlip>
UID = <sqluser>
USER = <sqluser>
PASSWORD = <pw>
7.) nano ~/.odbcinst.ini
[MySQL ODBC 5.3 Unicode Driver]
Driver=/usr/lib64/libmyodbc5w.so
UsageCount=1
[MySQL ODBC 5.3 ANSI Driver]
Driver=/usr/lib64/libmyodbc5a.so
UsageCount=1
[Default]
Driver=/usr/lib64/libmyodbc5a.so
UsageCount=1
8.) nano ~/.customer.sh
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64
export ODBCINI=$HOME/.odbc.ini
export ODBCSYSINI=$HOME
9.) Restarted VM
10.) I can successfully connect by calling
isql myodbc5w <user> <pw>
11.) Also this call works
myodbc-installer -d -l
MySQL ODBC 5.3 Unicode Driver
MySQL ODBC 5.3 ANSI Driver
Default
Now my problem and questions:
Why won't also my Smart Data Access access the MySQL (it seems to connect, but can't list the tables)? And what shall I set the "Configuration File" property with? And what's wrong with the odbc / odbcinst files, that only "Default" works?
I adapted the odbc file from an example which was shipped with the ODBC installation...
See screenshot for my SDA settings (only "Default" data source worked for me yet).
I'm working for days now on this problem, any help is appreciated! Thanks!
I resolved the same issue. I installed mariadb connector (not MySQL connector):
https://mariadb.com/kb/en/about-mariadb-connector-odbc/
wget https://downloads.mariadb.com/Connectors/odbc/connector-odbc-3.1.7/mariadb-connector-odbc-3.1.7-ga-rhel7-x86_64.tar.gz
tar -xvzf mariadb-connector-odbc-3.1.7-ga-rhel7-x86_64.tar.gz
cp lib/libmaodbc.so /lib64/
Next, i made an entry for Maria in .odbc.ini
[Maria]
Description = MariaDB 3.1.7 ODBC
Driver = /lib64/libmaodbc.so
SERVER = <your server>
and then:
enter image description here
I have two systems. my first system is ubuntu 16.04. which, work as remote.
and another is centos 6. which, run in virtually. In centos, freeswitch installed. I have to send data from freeswitch to remote system means ubuntu.
on centos, my configuration of odbc.ini as :
[freeswitch]
DRIVER = /usr/lib64/libodbcmyS.so
SERVER = <ipaddress>
USER = root
PASSWORD = <password>
PORT = 3306
DATABASE = freeswitch
OPTION = 67108864
and odbcinst.int as below:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib64/libmyodbc.so
Setup = /usr/lib64/libodbcmyS.so
FileUsage = 1
Threading = 0
after setup above code.
I have to check odbc connection. for this, command fire as :
isql -v freeswitch
but, it show error as :
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
wrong driver description arise this type of error.
I have set proper driver description. wrongly, setup description mention in driver field.
I think you need to change the line
DRIVER = /usr/lib64/libodbcmyS.so
to
DRIVER = MySQL
Thanks.
I installed unixODBC and MySql ODBC driver, but can not to connect ODBC DNS.
isql -v myodbc_mysql_dsn
I got this error :
Cannot connect to ODBC DSN:
[SQL ERROR]:[IM002][0][[unixODBC][Driver Manager]Data source name not found, and no default driver specified]|
my configration looks like this:
cat /etc/odbc.ini
[myodbc_mysql_dsn]
Description = test
Driver = MySQL5 # custom driver name
Server = localhost # or external IP if needed
Port = 3306 # or custom port if needed
Socket = /var/run/mysqld/mysqld.sock # socket, see above
Database = zabbix # MySQL DB name or empty
Option = 3
ReadOnly = No
cat /etc/odbcinst.ini
[MySQL5]
Description = ODBC for MySQL
Driver = /usr/lib/odbc/libmyodbc5.so
Setup = /usr/lib/odbc/libodbcmyS.so
#Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
#Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
UsageCount = 2 '
What should I do?
Here are some tips:
Use:
odbcinst -q -s
to see if you driver sees your datasources
Then
odbcinst -j
should show you filepaths to your *.ini
I have my unixodbc odbc.ini configure file like this:
[test]
Driver = /usr/local/lib/libmyodbc5-5.1.8.so
Description = Connector/ODBC 5.1.8 Driver DSN
SERVER = 127.0.0.1
PORT = 3306
USER = root
Password =
DATABASE = test
OPTION =
SOCKET =
And the problem is that it will not use the database as specified above, which is 'test'.
What I have to do is to manually execute a direct sql to change to database and run my query:
SQLExecDirect(stmt, "USE test", SQL_NTS);
SQLExecDirect(stmt, "SELECT * FROM mytable", SQL_NTS);
Any idea on how should I get rid of the 'USE test' which is a mysql command.
Why is unixodbc not setting 'test' as the default db since it's already specified in the conf file?
As on windows the driver manager (unixODBC in this case) only acts on the Driver tag, all other entries in the DSN are up to the driver to interpret. It doesn't notice there is a database= entry and know by magic that in this driver it should execute a "USE" command, and for another call SQLSetConnectAttr( SQL_ATTR_CURRENT_CATALOG ).
On my copy of the MySQL driver, it certainly uses the database= entry. However, I would check that 1. The copy of the driver you are using is built to use the unixODBC lib to access the shared config file (libodbcinst.so), or the driver is reading it directly, and is reading the same ini file as unixODBC. Possibly check with strace to see what ini is opened after the driver is loaded. Maybe try setting ODBCINI=/path/to/your/odbc.ini
[test]
Driver = /usr/local/lib/libmyodbc5-5.1.8.so
Description = Connector/ODBC 5.1.8 Driver DSN
SERVER = 127.0.0.1
PORT = 3306
USER = root
Password =
**DATABASE** = test
**OPTION** = **3**
**SOCKET** =
and can change options between 1,2 too