一、安装
sudo apt-get install pymysql
sudo pip3 install pymysql
二、python 与mysql 连接代码
from pymysql import *
try:
conn=Connection(host="localhost",port=3306,user="root",passwd="mysql",db='python3',charset="utf8")
cursor1=conn.cursor()
sql="insert into students(name) values('郭小二')"
#sql="update students set name= '王小二' where id = 9"
#sql="delete from students shere id=9"
cursor1.execute(sql)
conn.commit()
cursor1.close()
conn.close()
except Exception :
print("错误")
三、sql语句参数化
防止sql注入