我有一个脚本来创建一个包含命令行输出的变量。我想将此变量添加到 mysql 中的字段。 mysql 似乎不接受输入,因为 output
变量包含某些字符。我查看了文档,但我无法弄清楚如何让 mysql 只接受我向其发送的任何文本。 mysql 字段类型设置为 TEXT。
添加变量的 Bash 脚本
"INSERT INTO test (\`id\`, \`name\`, \`output\`, \`date\`) VALUES (null, '$name', '$output', '$date')"
错误
ERROR 1064 (42000) at line 1: 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 '': No such file or directory
cp: cannot stat '/etc/openvpn/easyrsa3/pki/private/' at line 18
答案 0 :(得分:0)
像这样更改命令
"INSERT INTO test (\`id\`, \`name\`, \`output\`, \`date\`) VALUES (null, \"$name\", \"$output\", \"$date\")"
答案 1 :(得分:0)
我最终通过在输出上使用 sed 解决了这个问题。
output_new=$(echo "$output" | sed s/"'"/"\\\'"/g)