# -*- coding: utf-8 -*- import MySQLdb conn = MySQLdb.connect("localhost","root","123456","test1" ) cur = conn.cursor() #建立游标 sql = "select * from student" insert_sql="insert into student (id,name) VALUES (6,'wanghaowanghao')" cur.execute(insert_sql) conn.commit() #提交 防止数据不一致 cur.execute(sql) result = cur.fetchall() #保存结果 for row in result: print row[0] print row[1] conn.close() # 关闭数据库