【问题标题】:Syntax error in mysql statement used in shell scriptshell脚本中使用的mysql语句中的语法错误
【发布时间】:2017-07-30 21:24:46
【问题描述】:

我目前正在编写一个 shell 脚本。
我想在 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

我哪里错了?
谢谢

【问题讨论】:

    标签: mysql shell ubuntu


    【解决方案1】:

    你不需要 --database=

    mysql -h "$host" --user="$user" --password="$pass" "$db" -e "UPDATE student SET balance=balance-$deduct WHERE pid=$pid";
    

    您也可以在查询中使用Use $db

    【讨论】:

    • 非常感谢。它帮助了我
    【解决方案2】:

    只需删除 --database=

    它应该工作。

    【讨论】:

      猜你喜欢
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      相关资源
      最近更新 更多