有人能告诉我如何使用shell脚本将多行通道(比如一个非常大的段落)插入MySQL数据库表吗?
以下是我目前正在使用的功能:
function dbPopulate()
{
command_ouput=$1
mysql -u $DB_USER -p$DB_PASSWORD << EOF
use $DB_NAME;
INSERT INTO $STATS_TABLE (script_runtime, command_output) VALUES (now(), $command_output);
EOF
}
注意:此处command_output的类型为&#34; longtext&#34;
答案 0 :(得分:1)
您需要在您尝试插入的字符串周围添加引号:
INSERT INTO `$STATS_TABLE` (script_runtime, command_output)
VALUES (now(), '$command_output');
我还在你要插入的表名周围加了一些反引号,这可以防止你的脚本在表名是保留关键字时失败。