使用pip安装
pip install mysqlclient
import MySQLdb
conn= MySQLdb.connect(host='localhost',port = 3306,user='root',db ='along')
cur = conn.cursor()
#cur.execute("create table if not exists student(id int(10) NOT NULL,name varchar(20)")
#插入一条数据
cur.execute("insert into student values('2','along')")
#修改查询条件的数据
cur.execute("update student set id='1' where name = 'Tom'")
#删除查询条件的数据
cur.execute("delete from student where name='Tom'")
#关闭游标
cur.close()
#在向数据库插入一条数据时必须要有这个方法,否则数据不会被真正的插入。
conn.commit()
#关闭数据库连接
conn.close()