在bash脚本中运行时删除查询执行非常慢

时间:2015-08-26 08:35:31

标签: mysql bash

我正在尝试在bash脚本中运行以下查询。

从mysql命令promt执行时,执行时间为0.06秒。

mysql> delete from assign_history where offer_id not in 
->('7','8','9','10','11','12','13','14','32','157','211','240','241','242','273',
->'274','275','310','312','313','314','326','328','329','333','334','335','336',
->'337','342','343','355','362','374','375','376','378','379','383','384','409','411') 
->and date(action_date) < "2015-06-25" order by id limit 1000;
Query OK, 1000 rows affected (0.06 sec)

但是当在bash脚本中运行它时,需要2分钟以上。

[root@localhost umap]# cat ./history_del.sh 
#! /bin/bash
echo $(date)
mysql -uroot -ppassword db_offers -e "delete from assign_history where offer_id not in ('7','8','9','10','11','12','13','14','32','157','211','240','241','242','273','274','275','310','312','313','314','326','328','329','333','334','335','336','337','342','343','355','362','374','375','376','378','379','383','384','409','411') and date(action_date) < "2015-06-25" limit 1000;"
echo $(date)

[root@localhost umap]# ./history_del.sh  
Wed Aug 26 19:08:45 IST 2015
Wed Aug 26 19:10:48 IST 2015

我也试过“mysql -Bse”选项。没有得到改善。有什么想法吗?

0 个答案:

没有答案