查询大表时查询进程被killed 本地内存被占满

当通过命令行执行大型MySQL查询时,可能会导致本地服务器内存被占满并被系统强制结束。解决方案是在查询命令中添加--quick参数,这将确保结果不会全部加载到内存中,从而防止内存耗尽。文章展示了两个例子,演示了如何使用该参数来避免内存问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[c-dag002 pang]$ mysql -hprod-ai.mysql.rds.aliyuncs.com -P5000 -udba -pdq4Xy -D device -e "select *  from t_tencent_statistic  where create_time < '2022-05-14 00:00:00' " > t_tencent_statistic.txt
mysql: [Warning] Using a password on the command line interface can be insecure.
Killed

[cloud-user@m2m-ags-biz-dag002 pang]$ free -h
              total        used        free      shared  buff/cache   available
Mem:            45G         30G         12G        2.8M        2.8G         15G
Swap:            0B          0B          0B
[clous-biz-dag002 pang]$ mysql -hprod-ai.mysql.rds.aliyuncs.com -P5000 -udba -pJqdq4 -D device --quick -e "select *  from t_tencent_statistic  where create_time < '2022-05-14 00:00:00' " > t_tencent_statistic.txt
mysql: [Warning] Using a password on the command line interface can be insecure.

[cloud-user@m2m-ags-biz-dag002 ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:            45G         30G        281M        2.9M         15G         15G
Swap:            0B          0B          0B
[cloud-user@m2m-ags-biz-dag002 ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:            45G         30G        285M        2.9M         15G         15G
Swap:            0B          0B          0B
[cloud-user@m2m-ags-biz-dag002 ~]$ cd pang/

当查询大表时,本地服务器上的内存被占满时,查询进程会备份系统kill 掉。

解决方法就是 使用  --quick 参数  该参数确保内存不被占满。

By default the entire result set is fetched in memory. If that becomes to much, the mysql client will be killed. You can start the mysql client with the --quick option to prevent this:

   mysql --quick -uname -ppwd wmap -e  ... 

Share

Follow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值