mysql can also be used in batch mode, allowing queries to be passed in from standard input and the results to be sent to standard output. The phrasebox example shows how to send a simple query to mysql via stdin and display the result of the query.
Like most other shell commands, mysql can be combined with other commands using pipes and input redirection. For example, the following shell command reads commands from file input_file and passes them to mysql. In turn, mysql authenticates the user, and if authentication succeeds, processes the commands and returns the results. The results are written to a file called output_file.
shell> mysql -u user -p < input_file > output_file
For more information on the pipe and input redirection features of your favorite shell, see the documentation for the shell.