Search code examples
mysqllinuxbashnamed-pipesmkfifo

Insert data into mysql table data from a FIFO pipe in linux continuously


I want to insert data from a fifo pipe into a mysql table, right now for me, this is possible until the fifo pipe process is killed,

the command :

$>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 " &

the data in the fifo pipe is inserted until the process of mysql is down by kill process.

Is possible insert data without kill the process of the fifo pipe data in?

Thanks!!


Solution

  • To clarify @JulienPalard's comment above, you should be able to achieve your aim with the following commands.

    (I use two different shell processes, whereas he uses one. For my description, try having both shells visible at once so that you can read output in one shell and write input in the other. If you know what you're doing, you can put the mysql process into the background and thus use only one shell.)

    Shell 1: output

    $ 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
    

    The last line above tells the named pipe to perpetually feed into the mysql process. Whenever you echo something into mypipe, it will be sent to the mysql process as standard input.

    After this, you won't get a new prompt because your tail command will run until you kill its process.

    Keep this shell open and its tail process running while you use your other shell process (Shell 2: input) to send commands to mysql.

    Shell 2: input

    $ 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