Reputation: 111
for some reason, bash script doesn't redirect output of mysql command in following snippet to designated file.
#!/usr/bin/bash
cmd="select * from foo > '/tmp/sample.txt'"
mysql --user=test --password=test <db name> --host=<hostname> --port=<portname> -e "$CMD"
above script redirect output to console instead of file
#!/usr/bin/bash
cmd="select * from foo INTO OUTFILE '/tmp/sample.txt' "
mysql --user=test --password=test <db name> --host=<hostname> --port=<portname> -e "$CMD"
when I replace ">" redirection operator with "INTO OUTFILE", I'm getting Access permission error
Upvotes: 2
Views: 7787
Reputation: 37930
What if you move the redirection operator (>
) out of the quotation marks?
cmd="select * from foo"
mysql --user=test --password=test <db name> --host=<hostname> --port=<portname> -e "$cmd" > /tmp/sample.txt
Upvotes: 5