如何在 MySQL 中查看 .csv 上传进度
我有一个非常大的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Linux 上,您可以打印有关文件描述符 (ls -l /proc//fd) 和文件位置读取器 (cat /proc//fdinfo) 的信息。所以:
查找 mysqld pid(在本例中:1234):
<代码>$ ps -ef | grep mysqld
mysql 1234 1 0 2 月 12 日? 00:00:55 /usr/sbin/mysqld
查找加载文件的文件描述符编号(在本例中:45):
$ sudo ls -l /proc/1234/fd
lr-x------ 1 root root 64 二月 13 10:56 45 -> /var/lib/mysql/db/Loaded_file.txt
打印有关该文件描述符的信息并检查已读取的字节数(在此示例中:494927872):
$ cat /proc/1234/fdinfo/45
邮政编码:494927872
flags: 0100000
您可以将此进度指示器(以字节为单位)与正在加载的实际文件大小进行比较。
除了步骤 1 和 2,您还可以使用“lsof”命令:
On Linux you can print info about file descriptor (ls -l /proc//fd), and file position reader (cat /proc//fdinfo). So:
Find mysqld pid (in this example: 1234):
$ ps -ef | grep mysqld
mysql 1234 1 0 feb12 ? 00:00:55 /usr/sbin/mysqld
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
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:
来自 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.
这里有几种方法...
设置会话事务隔离级别读取未提交
;然后 count(*) 将起作用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...
set session transaction isolation level read uncommitted
; Then count(*) will workselect
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>;