#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12

    MySQL Problem - connection dies after too many queries


    Hi, I'm writing an application and I'm testing it with large data for speed, but I can't even load it!

    MySQL dies after about 2000 queries.
    I'm going to need a few 100,000's to load it up.
    Anyone had this problem before ??

    Eli

    p.s. Does it have to do with me not closing something after each query ? Here's my db.py file that I use for each query :


    Code:
    #!/usr/bin/python
    
    import MySQLdb
    
    ### return a mysql cursor handle
    def connect():
    
        ### set database parameters
        host = "localhost"
        user = ""
        pwd  = ""
        db   = "video_store"
    
        ### connect
        db = MySQLdb.connect(host, user, pwd, db)
    
        ### return the db object
        return db
    
    
    ### this can be called on its own with a query as argument
    ### it returns the result
    def executeQuery(query):
    
        ### create a db object
        ### if not in this file, use: "mydb = db.connect()"
        mydb = connect()        
    
        ### get the db handle
        handle = mydb.cursor()
    
        ### execute the query
        handle.execute(query)
    
        ### get the results
        result = handle.fetchall()
    
        ### close the db connection
        mydb.close()
    
        ### return the results
        return result
  2. #2
  3. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Im not that much advanced in python, but as from what i know try adding a while loop in your code.. for example

    Code:
    result = handle.fetchall()
    while data in result:
     return data
    
    mydb.close()
    let me know if it works
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    that is kinda strange, you could try closing your handle/cursor although i dont know if that will do anything. If its MySQL which times out and not Python you might want to ask the MySQL boys why it would be doing this.. we can safly rule out that Pythons running out of memory though.

    Code:
        ...
        handle.close()
        ...
    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo