zoukankan      html  css  js  c++  java
  • mysql对执行结果进行html格式的输出?输出html格式?

    需求描述:

      在执行mysql命令的时候,有的时候需要将查询的结果输出到文件,如果想要html格式的,应该怎么输出,

      在此记录下操作的过程.

    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 13
    Server 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 its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    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>{&quot;name&quot;: &quot;????&quot;, &quot;status&quot;: 0, &quot;addtime&quot;: &quot;2017-10-10&quot;}</TD></TR><TR><TD>2</TD><TD>1002</TD><TD>[{&quot;name&quot;: &quot;????&quot;, &quot;status&quot;: 0, &quot;addtime&quot;: &quot;2017-10-11&quot;}, {&quot;name&quot;: &quot;????&quot;, &quot;status&quot;: 0, &quot;addtime&quot;: &quot;2017-10-12&quot;}]</TD></TR><TR><TD>3</TD><TD>1003</TD><TD>[{&quot;name&quot;: &quot;????&quot;, &quot;status&quot;: 0, &quot;addtime&quot;: &quot;2017-10-12&quot;}, {&quot;name&quot;: &quot;????&quot;, &quot;status&quot;: 0, &quot;addtime&quot;: &quot;2017-09-28&quot;}]</TD></TR></TABLE>3 rows in set (0.00 sec)
    
    mysql> notee;   #关闭记录日志.
    Outfile disabled.

    2.查看生成的文件及内容

    [mysql@testvm ~]$ ls -ltr
    total 12
    drwxrwxr-x 2 mysql mysql 4096 Jun  7 15:39 workspace
    -rw-rw-r-- 1 mysql mysql  720 Jul 17 13:30 html_test.html
    -rw-rw-r-- 1 mysql mysql  796 Jul 17 13:48 test.html

    3.如果不想要看到查询语句,可以在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 13:53 html_test.html

      4.查看文件内容

    备注:输出的文件中就不包括查询语句和查询了多少行的信息.

     5.如果不想要列标题使用-N选项

    [mysql@testvm ~]$ mysql --html -N -e "select * from test.tab_json;"  > html_test.html

     

     备注:已经输出了html格式的文件,并且不带列标题.

    小结:

    • 通过--html将查询结果以html格式输出,对其他的查询没有影响
    • 命令行中执行,使用>进行重定向输出,输出的结果中没有查询语句本身

    文档创建时间:2018年7月17日13:58:55

  • 相关阅读:
    Tomcat gzip果然强大,js文件压缩率50%以上
    URAL 1748
    URAL 1698
    [置顶] Spring中自定义属性编辑器
    Java-类库:lombok
    专业词汇:日志(log)
    SpringBoot-application:application.yml/配置文件详解
    SpringBoot:目录
    Java-Maven-pom.xml-porject-parent:parent
    Java-Maven-pom.xml-project-packaging:packaging(war/jar)
  • 原文地址:https://www.cnblogs.com/chuanzhang053/p/9323017.html
Copyright © 2011-2022 走看看