【问题标题】:Insert data into mysql table data from a FIFO pipe in linux continuously从linux中的FIFO管道连续向mysql表数据插入数据
【发布时间】:2011-06-12 19:15:21
【问题描述】:

我想将fifo管道中的数据插入到mysql表中,现在对我来说,这在fifo管道进程被杀死之前是可能的,

命令:

$>mkfifo /path/to/pipe
$>sudo chmod 666 /path/to/pipe
$>find \ -sl > /path/to/pipe & msql db1 -e"LOAD DATA INFILE '/path/to/pipe' INTO TABLE T1 " &

插入fifo管道中的数据,直到mysql的进程被kill进程关闭。

是否可以插入数据而不杀死fifo管道数据的进程?

谢谢!!

【问题讨论】:

  • 你的意思是你想让mysql命令在find命令完成后继续运行吗?
  • 也许你可以试试mysql中的sleep()
  • 不,我的意思是同时写入数据,这是从 fifo 管道传递到 mysql,我一直在寻找解决方案,我找到了 mysql:slurp,我正在尝试这个。
  • ajreal,睡眠()?这对我有什么帮助?
  • 您是否正在尝试执行以下操作: $ mkfifo /path/to/pipe $ sudo chmod 666 /path/to/pipe $ tail -f /path/to/pipe | msql db1 & find \ -sl > /path/to/pipe & ?

标签: mysql linux bash named-pipes mkfifo


【解决方案1】:

为了澄清@JulienPalard 上面的评论,您应该能够使用以下命令来实现您的目标。

(我使用两个不同的 shell 进程,而他使用一个。对于我的描述,尝试让两个 shell 同时可见,以便您可以在一个 shell 中读取输出并在另一个 shell 中写入输入。如果您知道自己在做什么这样做,您可以将mysql进程置于后台,从而只使用一个shell。)

外壳 1:输出

$ mkfifo mypipe # create a named pipe
$ chmod 666 mypipe # Give all users read-write access to the pipe
$ tail -f mypipe | mysql -umyName -p mySchema # pipe mypipe into mysql

上面的最后一行告诉命名管道永久地馈送到 mysql 进程中。每当您在 mypipe 中回显某些内容时,它将作为标准输入发送到 mysql 进程。

在此之后,您将不会收到新的提示,因为您的 tail 命令将一直运行,直到您终止其进程。

在您使用其他 shell 进程(Shell 2:输入)向 mysql 发送命令时,保持此 shell 处于打开状态并使其 tail 进程运行。

外壳 2:输入

$ echo 'show tables;' > mypipe # this will print output onto your *other* shell (Shell 1: output)
$ echo 'insert into mytable (1,2,3);' > mypipe # this performs an insertion

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 2016-02-21
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    相关资源
    最近更新 更多