mysql - 如何在mysql数据库中插入多行数据

标签 mysql linux bash unix

我的脚本中有一个命令是这样的

MESSAGE=`grep -Po 'MSG.\K[\w\s,.'\'',.:]*' < $FILENAME`

现在当这个命令运行时,我有一个看起来像这样的输出

Kohl's EDI will be down for scheduled maintenance starting at 12:30 am until
approximately 4:00 am central time on Wednesday June 22nd. Kohl's will not be
able to send or receive EDI or AS2 transmissions during this time. If your
company's AS2 software has an automated process to resend a file after a
failure, Kohl's encourages your company to enable the resend process. This     is
also a reminder for AS2 trading partners that Kohl's AS2 certificate will be
changing at 11:00 am central time on Tuesday June 21st.

现在,在 grep 全部内容后,我会将命令的结果传递给一个将要使用的变量,以便我可以将结果存储到 mysql 数据库中

问题是我将如何做?

最佳答案

确保您已从服务器连接到 mysql,然后您可以在插入语句中传递 MEASSGE 变量作为 \"$MESSAGE\" - \ 是因为包装有效插入语句的双引号消息。

测试:我没有足够大的列来存储您的整个消息,因此我将其略微修剪以适合该列:

> MESSAGE="Kohl's EDI will be down for scheduled maintenance starting at 12:30 am until
approximately 4:00 am central time on Wednesday June 22nd. Kohl's will not be
able to send or receive EDI or AS2 transmissions during this time. If your
company's AS2 software has an automated process to resend a file after a
"
> sql "insert into at_test_run (run_id,run_error) values ('10000111',\"$MESSAGE\");"
> sql "select run_id,run_error from at_test_run where run_id='10000111'"
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| run_id   | run_error                                                                                                                                                                                                                                                                                                       |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 10000111 | Kohl's EDI will be down for scheduled maintenance starting at 12:30 am until
approximately 4:00 am central time on Wednesday June 22nd. Kohl's will not be
able to send or receive EDI or AS2 transmissions during this time. If your
company's AS2 software has an automated process to resend a file after a
 |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

关于mysql - 如何在mysql数据库中插入多行数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37982128/

相关文章:

mysql - 在 MySQL 中同时使用 AUTO_INCREMENT 和 PRIMARY KEY 有什么意义?

mysql - SQL 排序,使得行仅在另一个列值相等的情况下排序

linux - Ubuntu 未启动至 GUI apt-get :/usr/local/lib/libstdc++. so.6:未找到版本 `GLIBCXX_3.4.15`

linux - 嵌入式 Linux 许可 LGPL/GPL/等

bash - 是否可以使用命令行确定 YARN 中当前事件的调度程序插件?

file - 仅对文件的一列进行排序

mysql - 使用左连接时 sql 连接不起作用

mysql删除触发器

c++ - 在 Linux 环境中开发 Visual Studio C++ 项目

通过 exec 对 find 的输出进行 Bash 变量替换