# sudo apt-get install python-mysqldb
# mysql> CREATE DATABASE ApingDB;
# mysql> use ApingDB;
# mysql> CREATE TABLE Nikon (time DATE,PriceA INT,PriceB INT);
# mysql> INSERT INTO Nikon values("2013-10-09","3199","3988");
import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root",passwd="password",db="ApingDB",charset="utf8")
cur=conn.cursor()
sql = 'INSERT INTO Nikon(time,PriceA,PriceB) values("2013-10-07","3199","3988")'
cur.execute(sql)
#sql = 'UPDATE Nikon set PriceB="4000" where time="2013-10-09"'
#cur.execute(sql)
cur.execute("select * from Nikon")
#输出显示
for row in cur.fetchall():
for r in row:
print r
conn.commit() #提交事务,否则操作无效
cur.close()
conn.close()