如何在 MySQL 中查看 .csv 上传进度

发布于 2024-11-03 01:50:37 字数 301 浏览 0 评论 0原文

我有一个非常大的 .csv 文件,我使用 LOAD DATA INFILE 命令将其加载到 mysql 中。由于需要很长时间,我想看看上传进度如何。

到目前为止我已经尝试过2种方法 - 首先,我简单地执行了 SELECT COUNT(*) 命令来查看上传过程中插入了多少行,但这总是返回 0 的计数。
其次,我尝试了 SHOW PROCESSLIST 并简单地查看了查询运行了多长时间。有时状态会显示“释放数据”或类似的内容。

有谁知道跟踪 LOAD DATA INFILE 命令进度的好方法?另外,有人知道如何跟踪插入率吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听风念你 2024-11-10 01:50:37

在 Linux 上,您可以打印有关文件描述符 (ls -l /proc//fd) 和文件位置读取器 (cat /proc//fdinfo) 的信息。所以:

  1. 查找 mysqld pid(在本例中:1234):

    <代码>$ ps -ef | grep mysqld

    mysql 1234 1 0 2 月 12 日? 00:00:55 /usr/sbin/mysqld

  2. 查找加载文件的文件描述符编号(在本例中:45):

    $ sudo ls -l /proc/1234/fd

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

  3. 打印有关该文件描述符的信息并检查已读取的字节数(在此示例中:494927872):

    $ cat /proc/1234/fdinfo/45

    邮政编码:494927872

    flags: 0100000

您可以将此进度指示器(以字节为单位)与正在加载的实际文件大小进行比较。

除了步骤 1 和 2,您还可以使用“lsof”命令:

$ 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

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
沫尐诺 2024-11-10 01:50:37

来自 http://www.stephenchu.com/ 2008/12/speed-up-your-mysql-data-load.html,如果你的表是Innodb类型,你可以使用SHOW INNODB STATUS,但你没有碰巧提到。

我链接到的页面也有一些很好的调整建议,可以通过这种方式加载数据来提高整体性能。

From http://www.stephenchu.com/2008/12/speed-up-your-mysql-data-load.html, you can use the SHOW INNODB STATUS IF your table is Innodb type, which you didn't happen to mention.

The page I linked to also has some good tuning suggestions to improve your overall performance with loading data in this manner.

为人所爱 2024-11-10 01:50:37

这里有几种方法...

  1. 设置会话事务隔离级别读取未提交;然后 count(*) 将起作用
  2. select
    rows_read 为“读”,
    round((rows_read/{linecount})*100, 2) as '完成',
    round(time/60, 2) as 'Elapsed',
    round(时间 * 100 / round((rows_read/<行数>)*100, 2) / 60, 2) 作为 '预计到达时间'
    来自 INFORMATION_SCHEMA.PROCESSLIST
    其中 id =;

Couple of approaches here...

  1. set session transaction isolation level read uncommitted; Then count(*) will work
  2. select
    rows_read as 'Read',
    round((rows_read/{linecount})*100, 2) as 'Complete',
    round(time/60, 2) as 'Elapsed',
    round(time * 100 / round((rows_read/<line count>)*100, 2) / 60, 2) as 'ETA'
    from INFORMATION_SCHEMA.PROCESSLIST
    where id = <id>;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文