https://pypi.org/project/PyMySQL/ pipinstallPyMySQL 1 PyMySQL操作和MySQLdb肖似,可参考 Python编程:MySQLdb模块对数据库的基本增批改查操作 代码示例 importpymysql#劝诱conn=pymysql.Connect(host="127.0.0.1",port=3306,user=
https://pypi.org/project/PyMySQL/
pipinstallPyMySQL
1
PyMySQL操作和MySQLdb肖似,可参考
Python编程:MySQLdb模块对数据库的基本增批改查操作
代码示例
importpymysql#劝诱conn=pymysql.Connect(host="127.0.0.1",port=3306,user="root",passwd="123456",db="test")#创建游标cursor=conn.cursor#实际sql大发国际,并复返受影响行数#rows=cursor.execute("insertintostudent(name,age,register_date,gender)"#"values('xiaoming',23,'2018-12-30','M')")#print(rows)data=[("student1",23,"2018-01-31","M"),("student2",24,"2018-02-27","M"),("student3",28,"2018-03-31","F"),("student4",26,"2018-04-30","M"),]#多条插入一齐实际#rows=cursor.executemany("insertintostudent(name,age,register_date,gender)"#"values(%s,%s,%s,%s)",data)#print(rows)#读取数据cursor.execute("select*fromstudent")print(cursor.fetchall)#提交事务conn.commit#关闭游标cursor.close#关闭劝诱conn.close