4

Okay, I log onto the MySQL command-line client as root. I then open or otherwise run a python app using the MySQLdb module as root. When I check the results using python (IDLE), everything looks fine. When I use the MySQL command-line client, no INSERT has occurred. If I change things around to _mysql instead of MySQLdb, everything works fine. I'd appreciate any clarification(s).

"Works" until IDLE/Virtual machine is reset:

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

2 Answers 2

17

You can use db.commit() to submit data or set db.autocommit() after _mysql.connect(...) to autocommit requests.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked for me, thanks for posting it (almost 3 years ago)!
This is exactly what I was looking for. Funnily enough most tutorials do not mention this which surprises me.
4

I think they use different autocommit settings. Use commit() after inserting data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.