我想從bash腳本傳遞參數到mysql腳本。在bash腳本是從bash傳遞參數到mysql腳本
#!/bin/bash
for file in `ls *.symbol`
do
path=/home/qz/$file
script='/home/qz/sqls/load_eval.sql'
mysql -u qz -h compute-0-10 -pabc -e "set @pred = '$path'; source $script;"
done
的load_eval.sql是
use biogrid;
load data local infile @pred into table lasp
fields terminated by ','
lines terminated by '\n'
(score, symbols);
當運行bash腳本,我得到了錯誤的消息:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@pred into table lasp ..
看來參數的值@ pred不會傳入mysql腳本。
嘗試回顯mysql語句'echo「mysql ...」'並且看看您是否在語句中看到錯誤或可能在此發佈回顯以幫助 –
@qing您可以使用-x運行此腳本並顯示輸出?還要將mysql行更改爲mysql --verbose -u qz -h compute-0-10 -pabc -e「set \ @pred ='$ path'; source $ script;」如果你可以發佈到一個pastebin我相信我可以幫忙。 –
'path'是變量名的不好選擇,因爲它對shell有着特殊的含義,使用不同的名字,例如'filepath'或'fullname' –