简体   繁体   English

在mysql中并发执行一个存储过程

[英]Concurrently execute a stored procedure in mysql

I am working in mysql.我在 mysql 工作。 I have a stored procedure which takes 1 min to run.我有一个需要 1 分钟才能运行的存储过程。 I have to run this procedure 10 times with different parameters.我必须用不同的参数运行这个程序 10 次。 How can I run the 10 instances of procedure simultaneously with different parameters?如何使用不同的参数同时运行 10 个过程实例? My procedure is such that no locking will happen between any 2 instances.我的程序是这样的,任何 2 个实例之间都不会发生锁定。

If you are using Linux then one solution is to create shell scripts and run them as cron jobs at a particular time.如果您使用的是 Linux,那么一种解决方案是创建 shell 脚本并在特定时间将它们作为 cron 作业运行。 Here is an example shell script.这是一个示例 shell 脚本。 This script is named as sql1.sh and it will write the current date to out1.txt这个脚本被命名为 sql1.sh,它会将当前日期写入 out1.txt

#!\bin\bash
date > out1.txt

so i have made sql1.sh till sql5.sh and the output written into out1.txt till out5.txt所以我已经将 sql1.sh 设为 sql5.sh 并将输出写入 out1.txt 直到 out5.txt

Here is the crontab file to execute the shell scripts at 19:37.这是19:37执行shell脚本的crontab文件。

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

Here is the output from out1.txt till out5.txt这是从 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

so instead of date command use mysql with suitable options to run your sql query.因此,不要使用日期命令,而是使用带有合适选项的 mysql 来运行您的 sql 查询。 This may not be efficient but will get the job done.这可能效率不高,但可以完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM