标题:Python3 pymysql连接MySQL数据库 出处:沧海一粟 时间:Tue, 17 May 2016 22:30:24 +0000 作者:jed 地址:http://www.dzhope.com/post/1012/ 内容: #!/usr/bin/python # -*- coding:utf8 -*- import pymysql #取得数据库连接对象 conn = pymysql.connect(host=‘127.0.0.1‘,port=3306,user=‘root‘,passwd=‘1234‘,db=‘python‘) #取得游标对象 cur = conn.cursor() #插入数据 cur.execute("INSERT INTO student(name,sex,age) VALUES(‘3‘, ‘0‘, ‘45‘)") conn.commit() #修改数据 cur.execute("UPDATE student SET age = 90 WHERE id = 2" ) conn.commit() #删除数据 cur.execute("DELETE FROM student WHERE name = ‘3‘") conn.commit() ########################################### # 数据发生改变时一定要conn.commit() # ########################################### #查询数据 cur.execute(‘SELECT *FROM student‘) for r in cur.fetchall(): print(r) cur.close() conn.close() Generated by Bo-blog 2.1.1 Release