我目前正在开发一个shell脚本
我想修改列的包含" balance" in"学生"在shell脚本中将表格设为"balance=balance-$deduct"
我在shell中执行以下行
mysql -h "$host" -u "$user" --password="$pass" --database="$db" -e "UPDATE student SET balance=balance-$deduct WHERE pid=$pid";
这里我正确指定了主机,用户名和密码,我在$deduct
中存储了一个数值
但是当我执行脚本时,我得到了以下错误:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE pid=132054' at line 1
我错在哪里?
感谢
答案 0 :(得分:0)
只需删除--database =
即可它应该工作。
答案 1 :(得分:0)
您不需要--database =
mysql -h "$host" --user="$user" --password="$pass" "$db" -e "UPDATE student SET balance=balance-$deduct WHERE pid=$pid";
您还可以在查询中执行Use $db