Search code examples
bashload-data-infile

BASH how to wait for mysql LOAD DATA LOCAL INFILE to complete


I have the following command in a BASH script. How can I check whether the command has completed uploading the file?

$(mysql -h "${1}" --user="${2}" --password="${3}" -D"${4}"   --skip-column-names --local-infile=1 -e "LOAD DATA LOCAL INFILE '$tempFile' INTO TABLE $tableName FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' " )

Solution

  • You can execute the query and then check the status by looking at $?:

    mysql -h "${1}" --user="${2}" --password="${3}" -D"${4}"   --skip-column-names --local-infile=1 -e "LOAD DATA LOCAL INFILE '$tempFile' INTO TABLE $tableName FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' "
    if [ $? ... ]; then do_something