参考:http://mysql-python.sourceforge.net/MySQLdb.html
http://dustman.net/andy/python/python-and-mysql
我已经在本机安装了mysql5.0, python版本为2.3.4, 并且安装了MySQL-python。
运行: python
insert 记录测试
import MySQLdb
db = MySQLdb.connect(db="test",user="root",passwd="password")
c=db.cursor()
c.execute("insert into file(fid,dmid,dkey,length,classid,devcount) values(%s,%s,%s,%s,%s,%s)",(0,0,'0',0,0,0))
db.commit()
c.close()
db.close()
select测试
>>> db = MySQLdb.connect(db="test",user="root",passwd="password")
>>> c=db.cursor()
>>> c.execute("select * from file where fid=%s",(0,))
1L
>>> c.fetchone()
(0L, 0, '0', 0L, 0, 0)
>>>