MySQLdb not INSERTING, _mysql works fine

Ok, I enter the MySQL command line client with root privileges. Then I open or otherwise launch the python application using the MySQLdb module as root. When I check the results with python (IDLE), everything looks great. When I use the MySQL command line client, no INSERT has occurred. If I change things to _mysql instead of MySQLdb, everything works fine. I would appreciate any clarification.

"Works" until the 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 Information: Intel x86 WinXP Python 2.5 MySQL 5.1.41 MySQL-Python 1.2.2

+4
source share
2 answers

You can use db.commit() to send data or install db.autocommit() after _mysql.connect(...) for auto-update requests.

+17
source

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

+4
source

Source: https://habr.com/ru/post/1306203/


All Articles