Query (two methods):
import mysqldb conn = mysqldb.connect (host = "localhost" , user = "root", passwd = "root", db = "fish") cursor = conn.cursor () cursor.execute ("Select * from polls_poll") Rows = cursor.fetchall () #获取所有结果集for row in rows: #从结果集中一条一条读出来 print "% d, %s, %s " % (row[0], row[1], row[2]) print " number of rows returned: %d " % cursor.rowcount cursor.execute (" select * from polls_poll ") while (True): row = Cursor.fetchone () #从结果集的开始, get a record, move a downstream label until the end returns NONE    IF row == noNe: break print "%d, %s, %s" % (row[0], row[1], row[2]) print "number of rows returned: %d" % cursor.rowcount cursor.close () conn.close ()
Insert:
Cursor.execute ("INSERT into (name, age) VALUES (' Bill ')") #返回受影响的行数, execution error return exception
Update:
Cursor.execute ("UPDATE both SET name = ' Jack ', age = ' WHERE name = ' Bill ') ' #返回受影响的行数, execution error returned exception
Python operation MySQL