1

I am trying to import an existing CSV file into my database and I want to see the progress. I usually use pipe viewer when I do my sql files but for csv files I cannot figure out how to do it.

I use macOX 10.15 and mysql 8.02 (not home-brew).

My idea was:

pv users.csv | mysql -u user -p -db < File/to/users.csv

Without using PV I just connect to my mysql change to my db and use this command:

LOAD DATA INFILE '/File/to/users.csv' INTO TABLE users FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n';

but I do not the see process.

1 Answer 1

1

Are you looking for something like this? https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

    create table watcher_tbl(time datetime, num_rows int);

    create event watch_event
    on schedule every 2 second
    do
    insert into watcher_tbl(time, num_rows) values (current_timestamp,
                                                    (select count(*) from watched_table));


    -- to see the progress.
    select * from watcher_tbl;

    -- to stop the event after loading is done.
    drop event if exists watch_event;
2
  • I will try this out and will update it. Currently, I just look at my database dir and look at the size of the table but this is very inaccuarte.
    – Shorty20
    Commented May 10, 2020 at 12:32
  • You may find that this "watcher" slows down the progress an annoying amount. Also, due to "transaction isolation", it may be useless. Consider "read uncommitted".
    – Rick James
    Commented May 10, 2020 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.