# 通过 pymysql 连接mysql
# pip3 install pymysql
import pymysql
# 创建连接
conn = pymysql.connect(host="192.168.4.4",port=3306,user="root",passwd="12345",db="student")
# 创建游标
cursor = conn.cursor()
# 执行sql,并返回受影响行数
effect_row = cursor.execute("select * from student")
# 一条一条取
# print(cursor.fetchone())
print(cursor.fetchall())
data = [
("N1","2017-10-11","M"),
("N2","2017-10-11","F"),
("N3","2017-10-11","F")
]
cursor.executemany("insert INTO student (name,register_data,gender) VALUES(%s,%s,%s)",data)
conn.commit()
cursor.close()
conn.close()