User avatar
RDK
Posts: 254
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Python Access using mysqlbd not working

Thu May 09, 2019 5:10 pm

I'm having a world of problems using the Python mysqldb libraries in Stretch on a Pi v3. I've done a fair amount of searching on this topic and it appears that I'm not alone!! When I use "import mysqldb" I get an error "ImportError: No module named mysqldb".

I've even posted this question on StackExchange: https://stackoverflow.com/questions/56 ... tionality which details my work so far.

In one of the references I found it suggested that I need to add this to my PATH variable:
/usr/local/mysql/bin/
but that folder does not exist on my Pi. What would be the correct address?

And help on this issue would be GREATLY appreciated....RDK

Andyroo
Posts: 4223
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Python Access using mysqlbd not working

Fri May 10, 2019 6:50 pm

Did you install mysqldb for Python 2 or Python 3?

The error infers that the module cannot be found for that version of Python.

How did you install it and did it give any errors? The Stackoverflow link seems to have a pile of steps but no notes on the results or exactly what was used :oops:
Need Pi spray - these things are breeding in my house...

User avatar
RDK
Posts: 254
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Python Access using mysqlbd not working

Sat May 11, 2019 4:44 am

Thanks for the interest. I'm using Python 2.7. This is a fresh install of Stretch on an Raspberry Pi v3. I have installed the following:
sudo apt-get install mariadb-server
sudo apt-get install python-mysqldb
sudo apt-get -y install python-mysql.connector
sudo apt-get install libmariadbclient-dev
sudo pip install PyMySQL

Since I posted this question I have discovered that one has to use this library import format "import MySQLdb", note the upper/lower case. If I do that python does not throw the import error. Now working to see if I can get the DictCursor to work.

I have gotten pymysql's DictCursor to work.

Thanks again.....RDK
Last edited by RDK on Sat May 11, 2019 3:11 pm, edited 1 time in total.

Andyroo
Posts: 4223
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Python Access using mysqlbd not working

Sat May 11, 2019 12:38 pm

Python is totally case centric :lol:

I hate the fact that libraries installed in pip and apt do not match the import names :twisted:

Glad your up and running.
Need Pi spray - these things are breeding in my house...

User avatar
RDK
Posts: 254
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Python Access using mysqlbd not working

Sat May 11, 2019 3:19 pm

Yes, having to find and then match case for a library is a bit annoying.

But, I'm now working with either MySQLdb or pymysql for using a DictCursor. Unlike pymysql and mysql.connector which use database for specifying the database name, MySQLdb uses db. Another thing which slowed me down.

Oh well, live and learn....RDK

Return to “Beginners”