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

  • SEARCH
  • Home
  • 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 3616154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:27:52+00:00 2026-05-18T22:27:52+00:00

I’m new to MySQL, and I have a question about the memory. I have

  • 0

I’m new to MySQL, and I have a question about the memory.

I have a 200mb table(MyISAM, 2,000,000 rows), and I try to load all of it to the
memory.

I use python(actually MySQLdb in python) with sql: SELECT * FROM table.

However, from my linux “top” I saw this python process uses 50% of my memory(which is total 6GB)

I’m curious about why it uses about 3GB memory only for a 200 mb table.
Thanks in advance!

  • 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-05-18T22:27:53+00:00Added an answer on May 18, 2026 at 10:27 pm

    There’s nothing inherently wrong with what you’re doing. If memory usage is expanding with the size of the query, then one of a few things is happening:

    • You’re leaking references to the results you’re receiving; for example, putting them in a list somewhere. I suspect you’d know if you were doing that.
    • The database bindings or underlying library isn’t freeing memory from previous rows while reading new rows from a query. This is usually a bug. It may happen normally if you have debugging features on, but it should not happen by default.

    Note that the underlying library may cache a certain amount of data, and you may see a significant amount of memory use as a result, but unless something is catastrophically wrong with the configuration it shouldn’t be 3GB.

    Here’s some simple SQLite code that reproduces what you’re doing. When run, it creates a trivial table of fifteen million rows, which is about 180 MB on disk for the version I’m using. It then SELECTs all of this data, throwing away the results, and sleeps so you can examine the result. The resulting process, on my system, uses only 15 MB.

    (Note that I ran the create_db and read_db passes with separate invocations; creating the database takes some time.)

    SQLite can handle this, and any production server-backed database like MySQL and Postgresql should be able to, too. SELECT results are a data stream, and databases should be able to handle streams of unlimited size easily.

    import sqlite3
    def create_db(conn):
        c = conn.cursor()
        c.execute('create table test (i integer)')
        conn.commit()
        max_val = 15000000
        chunk = 1000000
        for start in xrange(0, max_val, chunk):
            print "%i ..." % start
            for i in xrange(start, start + chunk):
                c = conn.cursor()
                c.execute('insert into test (i) values (?)', (i,))
            conn.commit()
    
    def read_db(conn):
        c = conn.cursor()
        c.execute('select * from test')
        for x in xrange(15000000):
            c.fetchone()
    
        print "Done"
    
        # Sleep forever, to examine memory usage:
        while True:
            time.sleep(1)
    
    def go():
        conn = sqlite3.connect('test.db')
    
        # Pick one:
        create_db(conn)
        # read_db(conn)
    
    if __name__ == "__main__":
        go()
    

    This doesn’t answer your question, but I wanted to make it clear that there’s nothing wrong with what you’re doing–you should not need to manually chunk queries, though in the end that’s probably the workaround you’ll need.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I don't have much knowledge about the IPv6 protocol, so sorry if the question
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

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.