Inserts don't appear to be happening
题
I'm using gevent with gevent-mysql (I also used pymysql to the same effect). It does selects just fine but no matter what I do I can't get it to run an insert. I'm out of ideas.
conn = geventmysql.connect(host='localhost', port=3306, user='root', db='content')
cur = conn.cursor()
cur.execute("insert into placement (placement_name, some_id) values ('static', 1)")
cur.close()
conn.close()
解决方案
If you are using a transactional storage engine (like InnoDB), you should check the value of the autocommit
variable: http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_autocommit
If it is 0
, you need to commit your transactions, either using a built in commit()
method or an execute("COMMIT")
call.
其他提示
If geventmysql works like the rest of the python DB APIs, you need to call commit in order to commit any changes to the database. Unless geventmysql
In the Python DB API, everything is implicitly a transaction. If you close the connection without committing, it gets rolled back. Do this:
conn.commit()
cur.close()
conn.close()