Connecting to Mysql using Python

#You will need to install the mysqldb module

# pip install MySQL-python
#pip install MySQLdb

import MySQLdb


db = MySQLdb.connect(host=”″, # your host
user=”user”, # your username
passwd=”passsword”, # your password
db=”db_name”) # name of the data base

cur = db.cursor()
cur.execute(“select * from TABLENAME;”)

# get the number of rows in the resultset
numrows = int(cur.rowcount)
print numrows
# get and display one row at a time.
for row in cur.fetchall():
print row


Here is a detailed list of things you can do using this module



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s