1

I have a shell script that has multiple load data statements that loads data from csv files into tables in MySQL. How to make use of GNU Parallel to execute these statements in parallel?

My shell script looks like this:

#!/bin/bash

mysql --defaults-extra-file=config.cnf -e "SELECT *
FROM table1
INTO OUTFILE '$path/table1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n';"

mysql --defaults-extra-file=config.cnf -e "SELECT *
FROM table2
INTO OUTFILE '$path/table2.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n';"

mysql --defaults-extra-file=config.cnf -e "SELECT *
FROM table3
INTO OUTFILE '$path/table3.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n';"

echo "END of script"

1 Answer 1

2
doit() {
  table="$1"
  tablepath="$2"
  mysql --defaults-extra-file=config.cnf -e "SELECT *
    FROM $table
    INTO OUTFILE '$tablepath' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n';"
}
export -f doit
parallel doit {/.} {} ::: path/table*.csv
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.