在mysql中并发执行存储过程

时间:2019-02-04 16:38:07

标签: mysql sql

我在mysql中工作。我有一个存储过程,需要1分钟才能运行。我必须使用不同的参数运行此过程10次。如何使用不同的参数同时运行10个过程实例?我的过程是在任何两个实例之间都不会发生锁定。

1 个答案:

答案 0 :(得分:0)

如果您使用的是Linux,则一种解决方案是创建Shell脚本并在特定时间将其作为cron作业运行。这是一个示例shell脚本。该脚本名为sql1.sh,它将当前日期写入out1.txt

#!\bin\bash
date > out1.txt

所以我将sql1.sh设置为sql5.sh,并将输出写入out1.txt直到out5.txt

这是crontab文件,用于在19:37执行shell脚本。

37 19 * * * /yourDirectory/sql1.sh
37 19 * * * /yourDirectory/sql2.sh
37 19 * * * /yourDirectory/sql3.sh
37 19 * * * /yourDirectory/sql4.sh
37 19 * * * /yourDirectory/sql5.sh

这是out1.txt至out5.txt的输出

Mon Feb 4 19:37:01 UTC 2019 - out1.txt
Mon Feb 4 19:37:01 UTC 2019 - out2.txt
Mon Feb 4 19:37:01 UTC 2019 - out3.txt
Mon Feb 4 19:37:01 UTC 2019 - out4.txt
Mon Feb 4 19:37:01 UTC 2019 - out5.txt

因此,代替date命令,使用带有适当选项的mysql运行您的sql查询。这可能效率不高,但可以完成工作。

相关问题