您当前的位置: 首页 >  sql

MySQL输出html格式文件

发布时间:2019-07-08 11:01:29 ,浏览量:0

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格式
				
					
					
						
						
							
							
								id
							

							
								uid
							

							
								info
							

						

						
							
							
								1
							

							
								1001
							

							
								{"name": "????", "status": 0, "addtime": "2017-10-10"}
							

						

						
							
							
								2
							

							
								1002
							

							
								[{"name": "????", "status": 0, "addtime": "2017-10-11"}, {"name": "????", "status": 0, "addtime": "2017-10-12"}]
							

						

						
							
							
								3
							

							
								1003
							

							
								[{"name": "????", "status": 0, "addtime": "2017-10-12"}, {"name": "????", "status": 0, "addtime": "2017-09-28"}]
							

						

					

				
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/,如需转载,请注明出处,否则将追究法律责任。

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    107766博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0473s