本帖最后由 郑全 于 2024-5-17 18:56 编辑
这对于巡检,尤其有用。
1.通过tee命令结合--html输出查询结果到html文件
[mysql@testvm ~]$ mysql --html #--html选项的意思产生html格式的输出.
Welcome to the MySQL monitor. Commands end with ;
or \g.Your MySQL connection id is 13Server version: 5.7.21-log MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates.
Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> tee test.html #tee命令表示将之后的内容记录到某个文件
Logging to file 'test.html'
mysql> select * from test.tab_json; #由于使用--html选项,输出的查询结果都是html格式
<TABLE BORDER=1><TR><TH>id</TH><TH>uid</TH><TH>info</TH></TR><TR><TD>1</TD><TD>1001</TD><TD>{"name": "????", "status": 0, "addtime": "2017-10-10"}</TD></TR><TR><TD>2</TD><TD>1002</TD><TD>[{"name": "????", "status": 0, "addtime": "2017-10-11"}, {"name": "????", "status": 0, "addtime": "2017-10-12"}]</TD></TR><TR><TD>3</TD><TD>1003</TD><TD>[{"name": "????", "status": 0, "addtime": "2017-10-12"}, {"name": "????", "status": 0, "addtime": "2017-09-28"}]</TD></TR></TABLE>3 rows in set (0.00 sec)
mysql> notee; #关闭记录日志.
Outfile disabled.
2.如果不想要看到查询语句,可以在shell命令行中执行
[mysql@testvm ~]$ mysql --html -e "select * from test.tab_json;" > html_test.html #注意是重定向符号>
[mysql@testvm ~]$ ls -ltr
total 12
drwxrwxr-x 2 mysql mysql 4096 Jun 7 15:39 workspace
-rw-rw-r-- 1 mysql mysql 796 Jul 17 13:48 test.html
-rw-rw-r-- 1 mysql mysql 720 Jul 17
3.如果不想要列标题使用-N选项
[mysql@testvm ~]$ mysql --html -N -e "select * from test.tab_json;" > html_test.html
|