为了澄清@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
命令将一直运行,直到您终止其进程。
当您使用其他shelltail
进程(Shell 2:输入)将命令发送到mysql
.
外壳 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