Please note that you can also use the document HERE for queries within the same script:
mysql -h$host -u$user -p$password db_dbname <<'EOF' select colA from TableA; select colB from TableB; select colC from TableC; EOF
Please note that I used 'EOF' and not EOF in the first line to prevent the script from content, to disable parameter substitution (especially, ` can be problematic)
Also note that there should be no spaces before the final EOF , unless you use <<- and not << - in this case leading tab characters are leading):
mysql -h$host -u$user -p$password db_dbname <<- 'EOF' ↠select colA from TableA; ↠select colB from TableB; ↠select colC from TableC; ↠EOF
(Replace ↠ with a tab character).
For more information on SOERE doc syntax, see the bash documentation .
source share