python 中操作 mysql
python 3.x
import pymysql conn=pymysql.connect(host,port,user,passwd,database,chartset)
cursor=conn.cursor()
row_count=cursor.execute('show databases;')
cursor.fetchall() #cursor.fetchmany(num) cursor.fetchone()
conn.commit()
cursor.close()
conn.close()
python2.x
import MySQLdb
conn = MySQLdb.connect(host, port, user,passwd,) # MySQLdb.Connection(host, port, user,passwd,)
cursor=conn.cursor()
.......