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
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
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.