Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:36:21+00:00 2026-06-14T03:36:21+00:00

I am working with MySQL 5.0 from python using the MySQLdb module. Consider a

  • 0

I am working with MySQL 5.0 from python using the MySQLdb module.

Consider a simple function to load and return the contents of an entire database table:

def load_items(connection):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM MyTable")
    return cursor.fetchall()

This query is intended to be a simple data load and not have any transactional behaviour beyond that single SELECT statement.

After this query is run, it may be some time before the same connection is used again to perform other tasks, though other connections can still be operating on the database in the mean time.

Should I be calling connection.commit() soon after the cursor.execute(...) call to ensure that the operation hasn’t left an unfinished transaction on the connection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:36:22+00:00Added an answer on June 14, 2026 at 3:36 am

    There are thwo things you need to take into account:

    1. the isolation level in effect
    2. what kind of state you want to “see” in your transaction

    The default isolation level in MySQL is REPEATABLE READ which means that if you run a SELECT twice inside a transaction you will see exactly the same data even if other transactions have committed changes.

    Most of the time people expect to see committed changes when running the second select statement – which is the behaviour of the READ COMMITTED isolation level.

    If you did not change the default level in MySQL and you do expect to see changes in the database if you run a SELECT twice in the same transaction – then you can’t do it in the “same” transaction and you need to commit your first SELECT statement.

    If you actually want to see a consistent state of the data in your transaction then you should not commit apparently.

    then after several minutes, the first process carries out an operation which is transactional and attempts to commit. Would this commit fail?

    That totally depends on your definition of “is transactional“. Anything you do in a relational database “is transactional” (That’s not entirely true for MySQL actually, but for the sake of argumentation you can assume this if you are only using InnoDB as your storage engine).

    If that “first process” only selects data (i.e. a “read only transaction”), then of course the commit will work. If it tried to modify data that another transaction has already committed and you are running with REPEATABLE READ you probably get an error (after waiting until any locks have been released). I’m not 100% about MySQL’s behaviour in that case.

    You should really try this manually with two different sessions using your favorite SQL client to understand the behaviour. Do change your isolation level as well to see the effects of the different levels too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on python and tried to fetch some data from Mysql Database
I am using python and specifically MySQLdb to fill a database, although a code
Im using a similar script as described here: long-polling info from mysql not working
I'm working on a project were I want to load data from a MySQL
I'm working on a project that requires me to programmatically create MySQL users from
I am working on porting over a database from a custom MSSQL CMS to
I am working on a MySQL database that is huge (about 120 tables). I
I'd like to find a simple example of working with remote MySQL base. I
I am working with Python MySQL, and need to clean a table in my
I have a working mysql query that retrieves data from table1. Now I will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.