我试图在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“选项。没有改善。有什么想法吗?
发布于 2015-08-26 08:59:06
有什么想法吗?
首先,您需要在查询字符串中转义双引号:\“2015-06-25”(尝试使用echo输出查询,您将看到原因)。我不知道,如果没有适当的引号,你的请求是如何工作的.
第二,更好的方法是将长行请求放在文件中,因此命令行如下所示:
mysql -uroot -ppassword db_offers <YOUR_FILEYOUR_FILE中的请求将与mysql提示符中的请求相同(当然,这里不需要转义双引号)。
是的,当您调用mysql实用程序时--连接到MySQL服务器可能会花费不可预测的长时间,所以这段时间包括2分钟(但是mysql提示符中的0.06秒不能!),所以您不能说连接到服务器需要多长时间,发送和执行查询需要多少时间。
要知道连接到mysql服务器需要多长时间,请尝试执行任何空查询(在mysql实用程序之前运行几秒钟后再执行),如:
time mysql -u user -ppassword -Bs <<<'select null'https://stackoverflow.com/questions/32221710
复制相似问题