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 · 20 comments

Comments

@shravankumar147
Copy link

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
Collaborator

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

Tried and worked Thanks

@kevalshah90
Copy link

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

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

@kevalshah90
Copy link

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

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

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

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

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

@gisael
Copy link

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!

@clcneogeek325
Copy link

Hey dudes I had the same problem, I did something that the developer we don´t do more often,
read the oficial documentation: https://dev.mysql.com/doc/connectors/en/connector-odbc-installation-binary-unix-tarball.html , you are welcome.

@jose598
Copy link
Contributor

jose598 commented Dec 28, 2021

Thank you! This helps me to find a solution!

@Seamen11
Copy link

Good day, I have followed your recommendations, but always get a problem: pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/mysql-connector-odbc-8.1.0-macos13-arm64/lib/libmyodbc8a.so' : file not found (0) (SQLDriverConnect)")
how can I fix it?(this file exist and cmd cat is running with this)

@v-chojas
Copy link
Contributor

Run otool -L on that file and see if there are missing dependencies. "file not found" can refer to the file itself or one of its dependencies.

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

No branches or pull requests

10 participants