具有大量记录的 MySQL 查询被杀死

标签 mysql command-line-interface

我从我的 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/

相关文章:

java - Mysql 将用户表与其他表连接起来

php - 在 Linux 命令行中运行 PHP

php - 如何在 Azure 中编辑命令行 php.ini 文件?

linux - 将具有相同行内容的列插入 cli 中的 csv

mysql - 当在普通表和从索引表中进行选择之间执行内连接时,索引是否有用

sql - 在一个查询中聚合分组结果集中的所有单个列 : is it possible?

sql - 需要有关 sql 查询的帮助

symfony - Doctrine :迁移:迁移。元数据存储不是最新的,请运行sync-metadata-storage命令解决这个问题

python - 打包一个要在控制台运行的Python项目 : pyproject. toml文件结构

mysql - 在MySQL语句中选择特定月份