import sys import MySQLdb conn = MySQLdb.connect (host = "localhost", user = "testuser", passwd = "testpass", db = "test") cursor = conn.cursor () cursor.execute ("DROP TABLE IF EXISTS test") cursor.execute (""" CREATE TABLE test (name CHAR(40), category CHAR(40)) """) cursor.execute (""" INSERT INTO test (name, category) VALUES ('snake', 'reptile'), ('frog','amphibian'), ('tuna', 'fish'), ('racoon', 'mammal') """) print "Number of rows inserted: %d" % cursor.rowcount raw_input("") cursor.execute ("SELECT name, category FROM test") while (1): row = cursor.fetchone () if row == None: break print "%s, %s" % (row[0], row[1]) print "Number of rows returned: %d" % cursor.rowcount raw_input("") cursor.close() conn.commit() conn.close()