删除数据
删除单条数据
#conding=utf-8
import MySQLdb
import random
try:
conn = MySQLdb.connect(
host = ‘127.0.0.1‘,
user = ‘root‘,
passwd = "123456",
port = 3306)
conn.select_db(‘python‘)# 选择pythonDB数据库
cur = conn.cursor()# 获取游标
cur.execute("delete from user where id=0")
cur.execute("select * from user")
for v in cur.fetchall():
print v
cur.close()
conn.commit()
conn.close()
print u"sql执行成功"
except Exception, e:
print e
删除多条数据
#conding=utf-8
import MySQLdb
import random
try:
conn = MySQLdb.connect(
host = ‘127.0.0.1‘,
user = ‘root‘,
passwd = "123456",
port = 3306)
conn.select_