我正在尝试匿名化一些学生形式我们的moodle.i我正在使用mysql skript。 我得到了错误。有人可以帮我解决这个问题。
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;`;
如果[$((ANZ))-gt 0] 然后 mysql -u $ USER -p $ PASSWD -h $ HOST -D $ DATABASE -e“SELECT id,username FROM $ TABLE WHERE deleted = 1而不是lastname ='anonym'和用户名如'%@%';” --skip-column-names -B> $ FILE; cat $ FILE |同时阅读TMP
DO
UserID=${TMP% *};
echo $UserID >> $RES_FILE;
echo "User $UserID wird anonymisiert...";
mysql -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "UPDATE $TABLE SET username='$A$UserID', email='a@nonym.de', firstname='$A', lastname='$A', icq='', skype='', yahoo='', aim='', msn='', phone1='', phone2='', institution='', department='', address='', city='', country='', url='', WHERE AND deleted =1 AND id=$UserID;"
;
`mysql -u $USER -p$PASSWD -h$HOST -D $DATABASE -e "UPDATE mdl_message SET subject='Neue Mitteilung von anonym' WHERE useridfrom=$UserID;"`;
`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 "Fertig!";
我有这个错误: 第1行的错误1064(42000):SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在第1行'AND deleted = 1 AND id = 715'附近使用正确的语法
第1行的错误1064(42000):您的SQL语法出错;检查与MariaDB服务器版本对应的手册,以便在第1行的'AND deleted = 1 AND id = 3478'附近使用正确的语法。
请帮助我。我是SQL新手。
非常感谢你的帮助。答案 0 :(得分:1)
你有
WHERE AND deleted =1 AND id=$UserID;
应该是:
WHERE deleted =1 AND id=$UserID;
AND
和WHERE
之间没有deleted