conn = MySQLdb.connect(host='db1', user='user', passwd='pass', db='db', port=3306)
cursor = conn.cursor()
count = int(sys.argv[1])
x = 0
while x < count:
x += 1
cursor.execute("INSERT INTO auth_group(name) VALUES(%s)", (str(x)))
#if I change %s to 'kkkk', it doesn't work either.
print str(x) + ' / ' + str(count)
print 'done'
但是...如果我进入“mysql -uuser -ppass db”,它会起作用:
mysql > INSERT INTO auth_group(name) VALUES('kkkkk');
我不知道这是否是个问题...但我之前遇到过复制问题。
我想向数据库中插入 99999 行。但它是空的。
mysql> select * from auth_group;
Empty set (0.33 sec)
最佳答案
如果没有特定的错误消息(换句话说,它似乎可以工作,但插入不粘),请确保在语句之后提交():
conn.commit()
关于python - 为什么我的脚本不起作用,但我可以手动插入到 mysql 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1869835/