Database Reference
In-Depth Information
% mysql
mysql> SELECT * FROM limbs WHERE legs=0;
+------------+------+------+
| thing | legs | arms |
+------------+------+------+
| squid | 0 | 10 |
| fish | 0 | 0 |
| phonograph | 0 | 1 |
+------------+------+------+
3 rows in set (0.00 sec)
For noninteractive use (when the input or output is redirected), mysql writes tab-
delimited output:
% echo "SELECT * FROM limbs WHERE legs=0" | mysql cookbook
thing legs arms
squid 0 10
fish 0 0
phonograph 0 1
To override the default output format, use the appropriate command option. Consider
this command shown earlier:
% mysql cookbook < inputfile | mail paul
Because mysql runs noninteractively in that context, it produces tab-delimited output,
which the mail recipient may find more difficult to read than tabular output. Use the -
t (or --table ) option to produce more readable tabular output:
% mysql -t cookbook < inputfile | mail paul
The inverse operation is to produce batch (tab-delimited) output in interactive mode.
To do this, use -B or --batch .
Producing HTML or XML output
mysql generates an HTML table from each query result set if you use the -H (or --
html ) option. This enables you to easily produce output for inclusion in a web page that
shows a query result. Here's an example (with line breaks added to make the output
easier to read):
% mysql -H -e "SELECT * FROM limbs WHERE legs=0" cookbook
<TABLE BORDER=1>
<TR><TH>thing</TH><TH>legs</TH><TH>arms</TH></TR>
<TR><TD>squid</TD><TD>0</TD><TD>10</TD></TR>
<TR><TD>fish</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>phonograph</TD><TD>0</TD><TD>1</TD></TR>
</TABLE>
The first row of the table contains column headings. If you don't want a header row, see
the next section for instructions.
Search WWH ::




Custom Search