简体   繁体   中英

How to run a single process multiple times in parallel using a UNIX shell script?

I am working on one of the MPP databases and would like to run a single SQL query using multiple sessions in python or UNIX shell script. Can somebody share your thoughts on spawning a SQL in python/UNIX utility. Any inputs would be appreciated. Thank you.

Code :-

for i in {1..$n}
do
        (  sh run_sql.sh test.sql touchstone_test & )
done

For python you could download the MySQLdb module. MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2.0 and is built on top of the MySQL C API. More info.

Depending on scale, you can choose either option.

If you have small tasks to accomplish, running a shell script is fine. Note that you can also pipe the query to the mysql CLI client, eg

mysql_cmd="mysql -h<host> -u<user> -p<pwd> <db>"
echo "SELECT name, id FROM myobjects WHERE ...." | $mysql_cmd

For a larger scale project, I would go with Python and the mysqldb interface that was mentioned already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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