MySQL

Install

From PyMySQL:

sudo apt-get install python-dev libmysqlclient-dev
pip install mysqlclient

Sample

import MySQLdb

conn = MySQLdb.connect(host = "localhost",
                       user = "testuser",
                       passwd = "testpass",
                       db = "test")
cursor = conn.cursor()
cursor.execute("SELECT VERSION()")
row = cursor.fetchone()
print "server version:", row[0]
cursor.close()
conn.close()

Note: For parameters you must use the %s format (for strings and numbers):

sql = 'SELECT id FROM positions WHERE building = %s AND pos = %s'
parameters = ('kitchen', 23)
self.cursor.execute(sql, parameters)

Issues

sh: mysql_config: not found

To solve this issue, I installed some MySQL dev packages:

sudo apt-get install libmysqlclient16-dev

Not sure if this is correct, but for more information see mysql_config question and the site.cfg file in the root of the archive.