How to see progress of .csv upload in MySQL

Tucker picture Tucker · Apr 21, 2011 · Viewed 9.9k times · Source

I have a very large .csv file, and I'm loading it into mysql with the LOAD DATA INFILE command. Because it takes so long, I'd like to see how far along the upload has progressed.

I've tried 2 methods so far- First I simply did a SELECT COUNT(*) command to see how many rows had been inserted as the upload was in progress, but that always returns a count of 0.
Second, I tried SHOW PROCESSLIST and saw simply how long the query has been running. sometimes the status says 'freeing data' or something to that effect.

Does anyone know a good way to track the progress of a LOAD DATA INFILE command? Also, does anyone know how to track the insertion rate?

Thanks

Answer

krzy-wa picture krzy-wa · Feb 13, 2013

On Linux you can print info about file descriptor (ls -l /proc//fd), and file position reader (cat /proc//fdinfo). So:

  1. Find mysqld pid (in this example: 1234):

    $ ps -ef | grep mysqld

    mysql 1234 1 0 feb12 ? 00:00:55 /usr/sbin/mysqld

  2. Find file descriptor number of your loaded file (in this example: 45):

    $ sudo ls -l /proc/1234/fd

    lr-x------ 1 root root 64 Feb 13 10:56 45 -> /var/lib/mysql/db/Loaded_file.txt

  3. Print info about that file descriptor and check number of bytes already read (in this example: 494927872):

    $ cat /proc/1234/fdinfo/45

    pos: 494927872

    flags: 0100000

You can compare this progress indicator (in bytes) to the actual file size being loaded.

Instead of step 1 and 2, you can also use 'lsof' command:

$ lsof /var/lib/mysql/db/Loaded_file.txt | grep mysql

COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME

mysqld    1234 youknowwho    45r   REG  252,0   190312 5505353 /var/lib/mysql/db/Loaded_file.txt