2016-06-16 55 views
0

手冊我有這樣的代碼:您的SQL語法有錯誤;檢查對應於您MariaDB的服務器

ANZ=`mysql -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "SELECT count(id) FROM $TABLE WHERE deleted=1 and not lastname='anonym';" --skip-column-names -B;`; 
if [ $((ANZ)) -gt 0 ] 
then 
mysql -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "SELECT id, username FROM $TABLE WHERE deleted=1 and not lastname='anonym' and username like '%@%';" --skip-column-names -B > $FILE; 

cat $FILE | while read TMP 

do 
echo "temp:" ${TMP% *}; 

    UserID=${TMP% *}; 
    echo $UserID >> $RES_FILE; 

    echo "User $UserID wird anonymisiert..."; 
echo $UserID; 

echo '`mysql -u$USER -p$PASSWD -h$HOST -D $DATABASE -e "UPDATE $TABLE SET username="'$A$UserID'", email='[email protected]', firstname='$A', lastname='$A', icq='', skype='', yahoo='', aim='', msn='', phone1='', phone2='', institution='', dep$ 
echo'  `mysql -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "UPDATE mdl_message SET subject='Neue Mitteilung von anonym' WHERE useridfrom=$UserID;"`'; 
echo'  `mysql -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "UPDATE mdl_message_read SET subject='Neue Mitteilung von anonym' WHERE useridfrom=$UserID;"`'; 
    VNAME=`mysql -N -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "SELECT firstname FROM $TABLE WHERE id=$UserID;"`; 
    NNAME=`mysql -N -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "SELECT lastname FROM $TABLE WHERE id=$UserID;"`; 
    `mysql -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "UPDATE mdl_event SET name='Meeting with your Student, anonym' WHERE name LIKE 'Meeting with your Student,%$VNAME $NNAME%';"`; 

done 
echo 
"Finish!" 

而我得到的錯誤是:

的mysql -u $ USER $ -p -h PASSWD $ HOST -D $ DATABASE -e「UPDATE $ TABLE SET username =」anonym611 [email protected]「,[email protected],firstname = anonym,lastname = anonym,icq =,skype =,yahoo =, aim =,msn =,phone1 =,phone2 =,institution =,department =,address =,city =,country =,url = WHERE deleted = 1 AND id = 611 [email protected];「 ./anonym.sh:Zeile 50:echo
mysql -u $ USER -p $ PASSWD -h $ HOST -D $ DATABASE -e「UPDATE mdl_message SET subject = Neue:command not found。 ./anonym.sh :Zeile 52:echo`mysql -u $ USER -p $ PASSWD -h $ HOST -D $ DATABASE -e「UPDATE mdl_message_read SET subject = Neue:command not found。

錯誤1064(42000)在第1行:您的SQL語法有錯誤;請檢查與您的MariaDB服務器版本對應的手冊,以獲取在第1行「[email protected]」附近使用的正確語法。

錯誤1064(42000)在第1行:您的SQL語法錯誤;檢查對應於您MariaDB的服務器版本在線路附近使用「[email protected]」正確的語法手冊1個

+0

請不要使用無關的標記。 –

回答

0

您的SQL錯誤是在這裏:

[...] WHERE deleted=1 AND id=611 [email protected];" 

你要麼需要在id=611之後關閉sql查詢,或者您的id是611 [email protected],在這種情況下,您需要在其周圍添加"。 @Bern Buffen答案後

編輯:

你一定要逃逸查詢的每個"

echo 'mysql -u$USER -p$PASSWD -h$HOST -D $DATABASE -e "UPDATE $TABLE SET username=\"$A$UserID\", email=\"[email protected]\", firstname=\"$A\", lastname=\"$A\", icq='', skype='', yahoo='', aim='', msn='', phone1='', phone2='', institution='', department='', address='', city='', country='', url='' WHERE deleted=1 AND id=\"$UserID\";"'; 
+0

非常感謝您的幫助, – 24al

+0

我的代碼是:echo''mysql -u $ USER -p $ PASSWD -h $ HOST -D $ DATABASE -e「UPDATE $ TABLE SET username =''$ A $ UserID'」, email='[email protected]',firstname ='$ A',lastname ='$ A',icq ='',skype ='',yahoo ='',aim ='',msn ='',phone1 ='',phone2 ='',院校='',dep $ 和runnung skript後得到這一個:[...] WHERE刪除= 1和id = 611 [email protected];「 – 24al

+0

我很抱歉,我的意思是這個代碼:echo''mysql -u $ USER -p $ PASSWD -h $ HOST -D $ DATABASE -e「UPDATE $ TABLE SET username =''$ A $ UserID'」,email ='[email protected]',firstname ='$ A',lastname ='$ A',icq ='',skype ='',yahoo ='',aim ='',msn ='',phone1 = '',phone2 ='',institution ='',department ='',address ='',city ='',country ='',url =''WHERE deleted = 1 AND id ='$ UserID';「 ''; 請幫助我。 – 24al

0

你不能在帶引號的字符串使用Quirles。使用單引號或反斜槓轉義

=「anonym611 [email protected]

+0

非常感謝。你的意思是:mysql -u $ USER -p $ PASSWD -h $ HOST -D $ DATABASE -e「UPDATE $ TABLE SET username =''$ A $ UserID'」,email='[email protected] ',firstname ='$ A',lastname ='$ A',icq ='',skype ='',yahoo ='',aim ='',msn ='',phone1 ='',phone2 ='' ,院校='',部門='',地址='',城市='',國家='',網址=''刪除= 1和ID ='$用戶ID';「';; 我該怎麼辦?請幫助我。我是Sql和PHP中的新成員。 – 24al

相關問題