Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to connect to the database: Can't open lib 'MySQL ODBC 3.51 Driver' #264

Closed
shravankumar147 opened this issue Aug 7, 2017 · 16 comments

Comments

@shravankumar147
Copy link

@shravankumar147 shravankumar147 commented Aug 7, 2017

Issue

unable to connect with the database:
Error:
('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'MySQL ODBC 3.51 Driver' : file not found (0) (SQLDriverConnect)")

Environment

  • Python: 2.7
  • pyodbc: latest from pip install
  • OS: ubuntu 16.04 x64
  • DB:MySQL
  • driver:MySQL ODBC 3.51 Driver
@gordthompson
Copy link
Contributor

@gordthompson gordthompson commented Aug 7, 2017

Have you actually installed the ODBC driver for MySQL? If so, did you register the driver so that it appears in odbcinst.ini, for example:

[MySQL ODBC 3.51 Driver]
Driver=/home/gord/Downloads/mysql-connector-odbc-3.51.30-linux-glibc2.3-x86-64bit/lib/libmyodbc3.so
UsageCount=1

You should be able to use the odbcinst -j command to check the location of odbcinst.ini. On Ubuntu it is typically /etc/odbcinst.ini.

@shravankumar147
Copy link
Author

@shravankumar147 shravankumar147 commented Mar 4, 2018

Tried and worked Thanks

@kevalshah90
Copy link

@kevalshah90 kevalshah90 commented Mar 19, 2019

It appears that I have MySQL ODBC 8.0 Driver installed. Content of odbcinst.ini -

[ODBC Drivers]
MySQL ODBC 8.0 Unicode Driver = Installed
MySQL ODBC 8.0 ANSI Driver = Installed

[ODBC Connection Pooling]
PerfMon = 0
Retry Wait =

[MySQL ODBC 8.0 Unicode Driver]
Driver = /usr/local/mysql-connector-odbc-8.0.15-macos10.14-x86-64bit/lib/libmyodbc8w.so

[MySQL ODBC 8.0 ANSI Driver]
Driver = /usr/local/mysql-connector-odbc-8.0.15-macos10.14-x86-64bit/lib/libmyodbc8a.so

However, I am getting the following error when running -

connstr = pyodbc.connect(Driver='{MySQL ODBC 8.0 Driver}',
server='localhost',
Database='dbname1',
UID='root',
PWD='xxxxxx')

Error: ('01000', u"[01000] [unixODBC][Driver Manager]Can't open lib 'MySQL ODBC 8.0 Driver' : file not found (0) (SQLDriverConnect)")

@v-makouz
Copy link
Contributor

@v-makouz v-makouz commented Mar 19, 2019

@kevalshah90 When specifying the driver in the connection string it has to match exactly what appears in odbcinst.ini, so in this case it should be either Driver='{MySQL ODBC 8.0 Unicode Driver}' or Driver={MySQL ODBC 8.0 ANSI Driver}

@kevalshah90
Copy link

@kevalshah90 kevalshah90 commented Mar 19, 2019

@v-makouz Thanks. I have attempted both of those, still getting the same error.

@kevalshah90
Copy link

@kevalshah90 kevalshah90 commented Mar 19, 2019

Error: ('01000', u"[01000] [unixODBC][Driver Manager]Can't open lib 'MySQL ODBC 8.0 Unicode Driver' : file not found (0) (SQLDriverConnect)")

Error: ('01000', u"[01000] [unixODBC][Driver Manager]Can't open lib 'MySQL ODBC 8.0 ANSI Driver' : file not found (0) (SQLDriverConnect)")

@v-makouz

@v-makouz
Copy link
Contributor

@v-makouz v-makouz commented Mar 19, 2019

@kevalshah90 If the name is correct, but the driver can't be loaded you can try to check is there is any problem with the driver file itself:
otool -L /usr/local/mysql-connector-odbc-8.0.15-macos10.14-x86-64bit/lib/libmyodbc8w.so

@v-makouz
Copy link
Contributor

@v-makouz v-makouz commented Mar 19, 2019

@kevalshah90 Also try
isql -v -k "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=<server>;UID=<user>;PWD=<password>"
It might give a more informative message about what it's not finding

@kevalshah90
Copy link

@kevalshah90 kevalshah90 commented Mar 19, 2019

Unfortunately, same message upon running the above line of code.

Can't open lib 'MySQL ODBC 8.0 Unicode Driver' : file not found (0) (SQLDriverConnect)").

I wonder if it is looking in the right place for the file? Is there a way to check?

@v-makouz
Copy link
Contributor

@v-makouz v-makouz commented Mar 19, 2019

@kevalshah90 If isql shows this and not the filename it means that the Driver Manager still can't match MySQL ODBC 8.0 Unicode Driver with an entry in odbcinst.ini. So the next thing to check is to run odbcinst -j, it will display (among other things) something like this:
DRIVERS............: /usr/local/etc/odbcinst.ini
Make sure that the odbcinst.ini that the Driver Manager expects is the one that has the MySQL entries

@kevalshah90
Copy link

@kevalshah90 kevalshah90 commented Mar 19, 2019

So, here are the paths for the driver -

[MySQL ODBC 8.0 Unicode Driver]
Driver = /usr/local/mysql-connector-odbc-8.0.15-macos10.14-x86-64bit/lib/libmyodbc8w.so

[MySQL ODBC 8.0 ANSI Driver]
Driver = /usr/local/mysql-connector-odbc-8.0.15-macos10.14-x86-64bit/lib/libmyodbc8a.so

whereas the output of odbcinst -j suggests /usr/local**/etc/**odbcinst.ini.

I wonder if that's the discrepancy?

@v-makouz
Copy link
Contributor

@v-makouz v-makouz commented Mar 19, 2019

@kevalshah90 I mean when you are looking at the odbcinst.ini, is that the same odbcinst.ini that's listed by odbcinst -j?

@kevalshah90
Copy link

@kevalshah90 kevalshah90 commented Mar 19, 2019

Different paths. The one I am looking at is /Library/ODBC/odbcinst.ini and the one listed by odbcinst -j is /usr/local/etc/odbcinst.ini.

I am guessing I need to add the MySQL entries to /usr/local/etc/odbcinst.ini. Umm..I am not seeing a way to access or edit those files?

@v-makouz
Copy link
Contributor

@v-makouz v-makouz commented Mar 19, 2019

@kevalshah90 You'll need to copy the entries (or the whole file) to /usr/local/etc/odbcinst.ini because that's the one that the Driver Manager is reading

To copy the whole file you can run cp /Library/ODBC/odbcinst.ini /usr/local/etc/odbcinst.ini which will overwrite everything in the destination.

@kevalshah90
Copy link

@kevalshah90 kevalshah90 commented Mar 19, 2019

Thanks for your help. For the record, MySQL ODBC 8.0 ANSI Driver works.

@gisael
Copy link

@gisael gisael commented Jul 20, 2020

@kevalshah90 You'll need to copy the entries (or the whole file) to /usr/local/etc/odbcinst.ini because that's the one that the Driver Manager is reading

To copy the whole file you can run cp /Library/ODBC/odbcinst.ini /usr/local/etc/odbcinst.ini which will overwrite everything in the destination.

You are amazing. Your very detailed explanation made my date. I appreciate your elaborated help here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants