[英]MySQLdb not INSERTING, _mysql does fine
Okay, I log onto the MySQL command-line client as root. 好的,我以root身份登录MySQL命令行客户端。 I then open or otherwise run a python app using the MySQLdb module as root.
然后我以root身份使用MySQLdb模块打开或以其他方式运行python应用程序。 When I check the results using python (IDLE), everything looks fine.
当我使用python(IDLE)检查结果时,一切看起来都很好。 When I use the MySQL command-line client, no INSERT has occurred.
当我使用MySQL命令行客户端时,没有发生INSERT。 If I change things around to _mysql instead of MySQLdb, everything works fine.
如果我将内容改为_mysql而不是MySQLdb,一切正常。 I'd appreciate any clarification(s).
我很感激任何澄清。
"Works" until IDLE/Virtual machine is reset: “工作”直到重置IDLE /虚拟机:
import MySQLdb
db = MySQLdb.connect(user='root', passwd='*******',db='test')
cursor = db.cursor()
cursor.execute("""INSERT INTO test VALUES ('somevalue');""",)
Works: 作品:
import _mysql
db = _mysql.connect(user='root', passwd='*******',db='test')
db.query("INSERT INTO test VALUES ('somevalue');")
System info: Intel x86 WinXP Python 2.5 MySQL 5.1.41 MySQL-Python 1.2.2 系统信息:Intel x86 WinXP Python 2.5 MySQL 5.1.41 MySQL-Python 1.2.2
您可以使用db.commit()
提交数据或在_mysql.connect(...)
之后设置db.autocommit()
_mysql.connect(...)
以自动提交请求。
I think they use different autocommit settings. 我认为他们使用不同的自动提交设置。 Use commit() after inserting data.
插入数据后使用commit()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.