Python & MySQL

J

jason.massey

Hi all,

I've got a weird problem. I was running Python 2.3 and MySQLdb and had
everything running fine.

Cutting to the chase: After upgrading to 2.4 (and latest modules) the
MySQLdb functions in Python can connect to the database, do queries and
do inserts.

Or rather, it seems to do inserts. If I just run in the Python command
line and manually connect to the database and do an insert and then a
query on what I just inserted the info is there.

However when I use SQLyog to look at the database the info isn't there.
When I close down Python, restart, reconnect and query the info isn't
there.

Info inserted from SQLyog is persistant.

Has anyone had any problems like this before?

thanks,

jason
 
J

jason.massey

Okay,

I had the brilliant idea right after posting to google the newsgroups
on this.

db = MySQLdb.connect(user=database_user,passwd=database_password)

db.autocommit(True) <--- One little line!


There ya go. Works like a champ. I swear I was pulling my hair out
yesterday over this.
 
S

Steve Holden

Hi all,

I've got a weird problem. I was running Python 2.3 and MySQLdb and had
everything running fine.

Cutting to the chase: After upgrading to 2.4 (and latest modules) the
MySQLdb functions in Python can connect to the database, do queries and
do inserts.

Or rather, it seems to do inserts. If I just run in the Python command
line and manually connect to the database and do an insert and then a
query on what I just inserted the info is there.

However when I use SQLyog to look at the database the info isn't there.
When I close down Python, restart, reconnect and query the info isn't
there.

Info inserted from SQLyog is persistant.

Has anyone had any problems like this before?

thanks,

jason
I suspect you are forgetting to commit your changes to the database, so
they are being rolled back when you close your connection.

regards
Steve
 
S

Steve Holden

Hi all,

I've got a weird problem. I was running Python 2.3 and MySQLdb and had
everything running fine.

Cutting to the chase: After upgrading to 2.4 (and latest modules) the
MySQLdb functions in Python can connect to the database, do queries and
do inserts.

Or rather, it seems to do inserts. If I just run in the Python command
line and manually connect to the database and do an insert and then a
query on what I just inserted the info is there.

However when I use SQLyog to look at the database the info isn't there.
When I close down Python, restart, reconnect and query the info isn't
there.

Info inserted from SQLyog is persistant.

Has anyone had any problems like this before?

thanks,

jason
I suspect you are forgetting to commit your changes to the database, so
they are being rolled back when you close your connection.

regards
Steve
 
A

Andy Dustman

Okay,

I had the brilliant idea right after posting to google the newsgroups
on this.

db = MySQLdb.connect(user=database_user,passwd=database_password)

db.autocommit(True) <--- One little line!

You would be better off executing db.commit() periodically (at the end
of your transaction).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,234
Messages
2,571,178
Members
47,811
Latest member
Adisty

Latest Threads

Top