Loading 5 million rows into Pandas from MySQL

前端 未结 3 1318
栀梦
栀梦 2021-02-06 08:36

I have 5 million rows in a MySQL DB sitting over the (local) network (so quick connection, not on the internet).

The connection to the DB works fine, but if I try to do

3条回答
  •  醉酒成梦
    2021-02-06 08:53

    The best way of loading all data from a table out of -any-SQL database into pandas is:

    1. Dumping the data out of the database using COPY for PostgreSQL, SELECT INTO OUTFILE for MySQL or similar for other dialects.
    2. Reading the csv file with pandas using the pandas.read_csv function

    Use the connector only for reading a few rows. The power of an SQL database is its ability to deliver small chunks of data based on indices.

    Delivering entire tables is something you do with dumps.

提交回复
热议问题