I believe the preferred way to connect to MySQL database from Python is with MySQLdb.

I'm relatively new to Python programming and it also seemed to be advised to write for Python 3, so I've been doing so.

But I can't see a python 3 package for mysqldb.

apt-cache show python-mysqldb says:

Depends: python (>= 2.6.6-7~), python (<< 2.8),


apt-cache search python3 | grep mysql

Gives no results.

How do I get started? Do I have to back-port my code to the old python? Thanks.

Edit after question was closed

So I thought this was to do with the Raspian repos not having the full complement of software, but it's just a Python thing and not related to RPI, so the editors were right to close the question.

However, if you've come across this, a great answer has been posed on stackoverflow before.

sudo apt-get install python-pip3
sudo pip3 install pymysql

Is what I went with.

closed as off-topic by goldilocks Oct 12 '15 at 20:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – goldilocks
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Raspbian is a form of Debian, and I agree with one of your comments re, at a glance for python3 there seems only to be the "pure python" mysql.connector package. However, I recommend you investigate the significance of this at our larger sibling site Unix & Linux (WRT Debian packages) or the parent site, Stack Overflow (WRT python 3 & mysql). – goldilocks Oct 12 '15 at 20:10

You need to know there are marked differences between Python 2 and Python 3. A script which works in one language may not work in the other.

Python 3 specific packages have names starting with python3.

python3-pymysql may be what you want.


sudo apt-get install python3-pymysql

  • Hmm. I don't have that package in my deb sources. Maybe I need to upgrade? I started on Wheezy – artfulrobot Oct 12 '15 at 17:55
  • I'm afraid I tend to forget I use jessie. Try "apt-cache search mysql | grep python" (I see you have done a similar search). – joan Oct 12 '15 at 18:05
  • Yeah, I'm upgrading to Jessie but still there's only python3-mysql.connector. I'll try that. – artfulrobot Oct 12 '15 at 18:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.