Karrigell/Test Mysql

Example using Mysql database

This simple program can be used to analyze your web server performance

this script might be saved as testmysql.py and tested on a Karrigell server used alone or behind Apache

import MySQLdb import time t1 = time.clock
 * 1) import MySQL module

db = MySQLdb.connect(host="localhost", user="root",  passwd="123456",db="test")
 * 1) connect

cursor = MySQLdb.cursors.DictCursor(db)
 * 1) create a cursor

cursor.execute("SELECT field1,field2 FROM table where field2 like '%%' limit 0,5000")
 * 1) execute SQL statement

result = cursor.fetchallDict print "Content-Type: text/plain\n\n"
 * 1) get the resultset as a tuple

for record in result: print "%s, %s" % (record['field1'], record['field2']) print " "
 * 1) iterate through resultset
 * 1)   print record[0], "-->", record[1]

Now you can get the time spent by the query

t2 = time.clock t3 = t2 - t1 print t3