MySQL输出html格式文件

MySQL输出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 12drwxrwxr-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格式输出,对其他的查询没有影响
  • 命令行中执行,使用>进行重定向输出,输出的结果中没有查询语句本身






About Me

........................................................................................................................

● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除

● 本文在itpub( http://blog.itpub.net/26736162 )、博客园( http://www.cnblogs.com/lhrbest )和个人weixin公众号( xiaomaimiaolhr )上有同步更新

● 本文itpub地址: http://blog.itpub.net/26736162

● 本文博客园地址: http://www.cnblogs.com/lhrbest

● 本文pdf版、个人简介及小麦苗云盘地址: http://blog.itpub.net/26736162/viewspace-1624453/

● 数据库笔试面试题库及解答: http://blog.itpub.net/26736162/viewspace-2134706/

● DBA宝典今日头条号地址: http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

........................................................................................................................

● QQ群号: 230161599 (满) 、618766405

● weixin群:可加我weixin,我拉大家进群,非诚勿扰

● 联系我请加QQ好友 646634621 ,注明添加缘由

● 于 2019-07-01 06:00 ~ 2019-07-31 24:00 在西安完成

● 最新修改时间:2019-07-01 06:00 ~ 2019-07-31 24:00

● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

........................................................................................................................

小麦苗的微店 https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麦苗出版的数据库类丛书 http://blog.itpub.net/26736162/viewspace-2142121/

小麦苗OCP、OCM、高可用网络班 http://blog.itpub.net/26736162/viewspace-2148098/

小麦苗腾讯课堂主页 https://lhr.ke.qq.com/

........................................................................................................................

使用 weixin客户端 扫描下面的二维码来关注小麦苗的weixin公众号( xiaomaimiaolhr )及QQ群(DBA宝典)、添加小麦苗weixin, 学习最实用的数据库技术。

........................................................................................................................

欢迎与我联系

 

 



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26736162/viewspace-2649799/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26736162/viewspace-2649799/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值