一、设置里添加pymysql
二、代码
import pymysql
DBHOST =‘localhost’
DBUSER =‘root’
DBPASS=‘root’
DBNAME=‘jt’
try:
db=pymysql.connect(user=DBUSER,password=DBPASS,db=DBNAME,host=DBHOST)
print(‘链接成功’)
cur=db.cursor()
cur.execute(‘drop table if exists student’)
sqQuery=“create table student(name varchar(10) not null ,age int,email char(20))”
cur.execute(sqQuery)
except pymysql.Error as e:
print(‘链接失败:’+str(e))