我从我的 shell 运行以下查询:
mysql -h my-host.net -u myuser -p -e "SELECT component_id, parent_component_id FROM myschema.components comp INNER JOIN my_second_schema.component_parents related_comp ON comp.id = related_comp.component_id ORDER BY component_id;" > /tmp/IT_component_parents.txt
查询运行了很长时间,然后被终止。
但是,如果我添加 LIMIT 1000
,那么查询会一直运行到最后,并且输出会写入文件中。
我进一步调查发现(使用 COUNT(*))将返回的记录总数为 239553163。
关于我的服务器的一些信息在这里:
MySQL 5.5.27
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+----------------------------+----------+
这是我监控的查询状态:
copying to tmp table on disk
sorting results
sending data
writing to net
sending data
writing to net
sending data
writing to net
sending data ...
KILLED
大家猜猜这里出了什么问题?
最佳答案
mysql 客户端可能内存不足。
使用 --quick 选项不在内存中缓冲结果。
关于具有大量记录的 MySQL 查询被杀死,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18104843/