Database Reference
In-Depth Information
to connect the two programs directly with a pipe, avoiding the need for an intermediary
file:
% mysqldump cookbook | mysql -h other-host.example.com cookbook
Program-generated SQL also can be useful for populating a table with test data without
writing the INSERT statements by hand. Create a program that generates the statements,
then send its output to mysql using a pipe:
% generate-test-data | mysql cookbook
Recipe 4.6 discusses mysqldump further.
1.7. Controlling mysql Output Destination and Format
Problem
You want mysql output to go somewhere other than your screen. And you don't neces‐
sarily want the default output format.
Solution
Redirect the output to a file, or use a pipe to send the output to a program. You can also
control other aspects of mysql output to produce tabular, tab-delimited, HTML, or XML
output; suppress column headers; or make mysql more or less verbose.
Discussion
Unless you send mysql output elsewhere, it goes to your screen. To save output from
mysql in a file, use your shell's redirection capability:
% mysql cookbook > outputfile
If you run mysql interactively with the output redirected, you can't see what you type,
so in this case you usually also read the input from a file (or another program):
% mysql cookbook < inputfile > outputfile
To send the output to another program (for example, to mail query results to someone),
use a pipe:
% mysql cookbook < inputfile | mail paul
The rest of this section shows how to control mysql output format.
Producing tabular or tab-delimited output
mysql chooses its default output format by whether it runs interactively or noninterac‐
tively. For interactive use, mysql writes output to the terminal using tabular (boxed)
format:
Search WWH ::




Custom Search