Using MySQL in Python - xtyang/BabyStepsTwitter GitHub Wiki

There are several kinds of module that connecting python and sql database

MySQLdb module used in BabySteps

MySQL-python 1.2.3 for Windows

[Writing MySQL Scripts with Python DB-API] (http://www.kitebird.com/articles/pydbapi.html)

Official MySQL connector with Python

In MySQL official website, there is a clear instruction on how to utilize mysql in python.

After you installed mysql for python, don't forget to add that folder in Pydev Path.(source) (Project->Properties->PyDev-PYTHONPATH->External Liberaries->Add source folder)

[Connecting MySQL database through Python] (http://dev.mysql.com/doc/connector-python/en/myconnpy_example_connecting.html)

import mysql.connector

cnx = mysql.connector.connect(user='scott', password='tiger', host='127.0.0.1', database='employees')

cnx.close()

[Query example] (http://dev.mysql.com/doc/connector-python/en/myconnpy_example_cursor_select.html)

cnx = mysql.connector.connect(user='scott', database='employees')

cursor = cnx.cursor()

query = ("SELECT first_name, last_name, hire_date FROM employees WHERE hire_date BETWEEN %s AND %s")

hire_start = datetime.date(1999, 1, 1)

hire_end = datetime.date(1999, 12, 31)

cursor.execute(query, (hire_start, hire_end))