Search code examples
mysqllinuxbashlinux-mintmpv

Call external program from mysql


How can I call an external program from mysql?

I am a complete beginner at this, on Linux Mint 20, I created a database of all my video files, the paths of the videos are all listed in a table.

I can access the DB using Bash with:

mysql -u root -proot -e "use collection; select path from videos where path Like '%foo%' or path Like '%bar%'"

To search for what I want, but now I want to pipe the chosen vid(s) to MPV/VLC, whatever.

Apart from the fact I am doing it as root, am I going about this the wrong way?

I just want to perform quick searches in a terminal, then fire up the vid(s).

Thanks a lot, folks.


Solution

  • If I'm understanding correctly. You want to query your db for a specific type of file or path and then you want to use the result of your query to open up the files?

    You don't open the program from MySQL, but you could open it from bash.

    Figure out what the bash command is to open that program and use the output of your query to run over a loop in bash to open, one by one, the results you got from your query.

    Alternatively you can output the results to a temporary file and read from it with bash:

    mysql -user -pass -e "YOUR QUERY" > /tmp/output.txt

    If you can get the right output in your output.txt file, I would look into reading from that file in bash with a loop. Something like:

    while IFS= read -r line
    do
        mpv "$line"
    done < output.txt