title: Fastest way to read huge MySQL table in python
body: <p>I was trying to read a very huge MySQL table made of several millions of rows. I have used <code>Pandas</code> library and <code>chunks</code>. See the code below:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import pymysql.cursors
  
  connection = pymysql.connect(user='xxx', password='xxx', database='xxx', host='xxx')
  
  try:
      with connection.cursor() as cursor:
          query = "SELECT * FROM example_table;"
  
          chunks=[]
  
          for chunk in pd.read_sql(query, connection, chunksize = 1000):
              chunks.append(chunk)
          #print(len(chunks))    
          result = pd.concat(chunks, ignore_index=True)
          #print(type(result))
          #print(result)
  
  finally:
      print("Done!")
  
      connection.close()
  </code></pre>
  
  <p>Actually the execution time is acceptable if I limit the number of rows to select. But if want to select also just a minimum of data (for example <strong>1 mln of rows</strong>) then the execution time dramatically increases.</p>
  
  <p>Maybe is there a better/faster way to select the data from a relational database within python?</p>