一、 连接MySQL
import pymysql
conn = pymysql.connect('10.36.132.6', 'root', 'root', 'mydb2')
cursor = conn.cursor()
sql = 'select version()'
cursor.execute(sql)
res = cursor.fetchone()
print(res)
cursor.close()
conn.close()
二、插入数据
import pymysql
conn = pymysql.connect('localhost', 'root', 'root', 'mydb2')
cursor = conn.cursor()
sql = 'insert into person(name, age) values("aa", 20)'
try:
cursor.execute(sql)
conn.commit()
except:
conn.rollback()
cursor.close()
conn.close()
三、删除数据
import pymysql
conn = pymysql.connect('localhost', 'root', &#