Using the Client in Batch Mode


shell> echo 'SELECT 1 + 1' | mysql -u some_user -p



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.



MySQL Phrasebook. Essential Code and Commands
MySQL Phrasebook
ISBN: 0672328399
EAN: 2147483647
Year: 2003
Pages: 130

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net