import MySQLdb
connet=MySQLdb.connect( host='localhost', port='8808', user='amdin', password='****', db='db_name')
#获取游标
cur=connet.cursor()
cur.execute("select *from student")
cur.close()
connet.commit()
connet.close()
#一条数据插入
sqli="insert into student values("%s","%s","%s","%s")"
cur.execute(sqli,('','','',''))
#多条数据插入 :executemany()方法
sqli="insert into student values("%s","%s","%s","%s")"
cur.executemany(sqli,{
('1','b','32','xiaoli'),
('2','b','33','xiaoai'),
('3','c','34','xiaozhen'),
('4','d','36','xiaohong')
})
接受全部的返回行结果 cursor.fetchall()
获取下个一查询结果集,是一个对象 fetchone()