python 链接mysql数据库:
import MySQLdb
from twisted.enterprise import adbapi
import MySQLdb.cursors
dbuser = 'scott'
dbpass = 'scott'
dbname = 'sina'
dbhost = '127.0.0.1'
dbport = '3306'
conn = MySQLdb.connect(user=dbuser,passwd=dbpass,db=dbname,host=dbhost,charset='utf8',use_unicode=True)
cursor = conn.cursor()
ret = cursor.execute("""select * from fans """)
rows = cursor.fetchall()
for row in rows:
print row
conn.commit()
//提交更改
cursor.close()
//关闭实例
conn.close()
//关闭连接