Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQLdb not INSERTING, _mysql does fine

Tags:

python

mysql

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

like image 417
Mad_Casual Avatar asked Nov 30 '22 18:11

Mad_Casual


2 Answers

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

like image 117
zoli2k Avatar answered Dec 06 '22 17:12

zoli2k


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

like image 43
Yaroslav Avatar answered Dec 06 '22 17:12

Yaroslav