I'm trying to run a query on a remote server from by bash script. Problem is, I have to use single quotes inside of the query which already has surrounding single quotes.
My code:
# note: $line has ` in it, as this is a SQL query
ssh server "mysql --defaults-extra-file=$SQL_CREDS_FILE $R_DB $t -e '$line INTO OUTFILE \"\'\"$DIR/$tbl_count.csv\"\'\" FIELDS TERMINATED BY \"\'\",\"\'\" ENCLOSED BY \"\'\"\"\'\" LINES TERMINATED BY \"\'\"\n\"\'\"'"
The error I'm seeing upon running this code:
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
Example of working MYSQL query:
mysql -u user -pPassword database -e 'select `id`,`title`,`name`,`description`,`icon`,`creation_date` as `created_at`,`mutation_date` as `created_at` from achievement;'
$line? I think it might solve the issue.\`but unfortunately no luck there.$(...)around the command is wrong, unless you specifically expect thesshcommand to return a command which should be evaluated locally (which in turn seems like a very risky construct; but really, I can't believe that's what you want here).INTO OUTFILEpart that works when typed inside mysql session.