TIM*_*MEX 6 python mysql database
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'
Run Code Online (Sandbox Code Playgroud)
但是......如果我进入"mysql -uuser -ppass db",它可以工作:
mysql > INSERT INTO auth_group(name) VALUES('kkkkk');
Run Code Online (Sandbox Code Playgroud)
我不知道这可能是一个问题......但我之前遇到了复制问题.
我想将99999行插入数据库.但它是空的.
mysql> select * from auth_group;
Empty set (0.33 sec)
Run Code Online (Sandbox Code Playgroud)
Jar*_*die 17
如果没有特定的错误消息(换句话说,它似乎工作,但插入不粘),请确保在语句后提交():
conn.commit()
Run Code Online (Sandbox Code Playgroud)