参数: -s
安静模式,减少输出,比如表头(Silent mode. Produce less output.)。
参数:-r
输出的信息不进行转义,如果没有此参数,某些特殊字符将会被转义(Newline, tab, NUL, and backslash are written as \n, \t, \0, and \\.)
参数:-t
输出为表格形式(Display output in table format),在命令行方式默认输出为表格形式。但是作为脚本时如果要输出为表格形式那么就必须加上此参数。
参数:-H
输出为HTML形式(Produce HTML output.)。
使用示例 示例一
[iyunv@node34 root]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 3.23.58-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
[iyunv@web exam_server]# ./db.sh
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14687
Server version: 5.1.48-community-log MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quit
Bye
[iyunv@web exam_server]#
下面的命令将mysql的查询结果输出为HTML文本,这个可以用在shell脚本中。
[iyunv@web exam_server]# ./db.sh -H <<EOF
show tables;
EOF
<TABLE BORDER=1><TR><TH>Tables_in_exam</TH></TR><TR><TD>exam_paper_info</TD></TR><TR><TD>exam_paper_question</TD></TR><TR><TD>exam_question_info</TD></TR><TR><TD>exam_user_answer</TD></TR><TR><TD>exam_user_info</TD></TR><TR><TD>exam_user_paper</TD></TR></TABLE>
下面的命令将mysql的查询结果输出为表格形式,这个可以用在shell脚本中。注:在shell脚本中要输出表格形式,必须加上-t参数。
[iyunv@web exam_server]# ./db.sh -t <<EOF
> select count(*) as "未评分数量", count(distinct question_seq) as "未评分题数"
> from exam_user_answer
> where degrees is null;
> EOF
+------------+------------+
| 未评分数量 | 未评分题数 |
+------------+------------+
| 0 | 0 |
+------------+------------+
[iyunv@web exam_server]#