0
我想將我的sql表數據導出到csv,但有這些錯誤。我真的與雙引號和單引號混淆。使用bash腳本將mysql表數據導出到csv
#!/bin/bash
mysql -u root -pH0tjava1 -B -e 'SELECT CONCAT("sshpass -p ""Password"" rsync -avvtzh -e ""ssh -o StrictHostKeyChecking=no"" --log-file=""/home/toor/rsync2.log""", login,"@", ftp_addr, " :", camera_name,"/", "/",`\ 'home`',"/",login, "/", camera_name) INTO OUTFILE '/tmp/rsynctest3.csv' lines terminated by '\r\n' from inteliviz.cameras;"
Errors:
/usr/local/bin/rsync.sh: line 8: syntax error near unexpected token `)'
/usr/local/bin/rsync.sh: line 8: ` mysql -u root -pH0tjava1 -B -e "select CONCAT ("sshpass -p "Pa55word" rsync -avvtzh -e "ssh -o StrictHostKeyChecking=no" --log-file= "/home/toor/rsync2.log", login,camera_name,ftp_addr) INTO OUTFILE '/tmp/rsynctest3.csv' lines terminated by '\r\n' from inteliviz.cameras;"'
/usr/local/bin/rsync.sh: line 8: unexpected EOF while looking for matching ``'
/usr/local/bin/rsync.sh: line 11: syntax error: unexpected end of file
[如何以CSV格式輸出MySQL查詢結果?](http://stackoverflow.com/q/356578/3776858) – Cyrus
首先在客戶端界面中處理您的查詢。一旦你有一個工作查詢,你可以擺弄引號和單引號從腳本運行它。 –
感謝賽勒斯,我已經經歷了這個問題,但仍然失敗了這個腳本來讓它工作。 –