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 8086339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:24:56+00:00 2026-06-05T18:24:56+00:00

I am trying to update a database with values from a csv file, the

  • 0

I am trying to update a database with values from a csv file, the following is my code:

import MySQLdb as mdb
import sys
import csv

con = None
command = ''
new_name_list = []
old_name_list = []
duplicates = []
update_list = []
file = 'csv_file.csv'
listReader = csv.reader(open(file, 'r'))
for row in listReader:
    new_name_list.append(row)

try:

    con = mdb.connect('localhost', 'root', 'mypassword', 'mydb')
    con.autocommit(True)

    cur = con.cursor()
    cur.execute("SELECT fil_name FROM file WHERE fil_name like 'boy%' and fil_job_id=1")    

    numrows = int(cur.rowcount)

    for i in range(numrows):
        file_name = cur.fetchone()
    old_name_list.append(file_name[0])

    d = dict(new_name_list)

    for n in old_name_list:
        try:
            print n + " has been updated to " +  d[n]
            command = "UPDATE file SET fil_name='" + d[n] + "' WHERE fil_name='" + n + "'"
            cur.execute(command)
        except KeyError:
            duplicates.append(n)

except mdb.Error, e:

    print "Error %d: %s" % (e.args[0],e.args[1])
    sys.exit(1)

finally:    

    if con:    
        con.close()

It takes about 2-3 seconds for each print to appear, which leads me to think that the update execution is being made slowly. I have a lot of values to update and this should not be the speed that it should be executing (given that I was able to get a quick printout of all the values of d[n] )

Is there anyway to speed up the updating?

EDIT: The database is using InnoDB engine

  • 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-05T18:24:58+00:00Added an answer on June 5, 2026 at 6:24 pm

    According to your description,each print cost 2~3 seconds,so i think the problem maybe of this:

    1. do you have your fil_name column of table file indexed?
    2. you make auto_commit be true,each update is a transaction commited.

    If the case is 1,just create index on that column,do not make table scan on updating.

    If the case is 2,@dave gives a good answer.

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

Sidebar

Related Questions

I'm trying to update my database i.e. a MS Access file, I want to
I am trying to Update a table in an access database from C#. It
I'm trying to call a row update from php to an mysql database. It
I am trying to update the database to show that something has been uploaded.
I'm trying to update a field in the database to the sum of its
I'm trying to update a row in my database but it's not running. Below
So I'm trying to update an object in my MS SQL 2005 database using
I am trying to update an existing record in a database using CoreData, but
I'm trying to insert status update into my database in table called blabbing, but
Hi iam trying to make an update trigger in my database. But i get

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.