详解MySQL的tee功能 并利用其记录相关操作

php中文网
发布: 2016-06-07 17:19:13
原创
1540人浏览过

由于经常对mysql数据库进行大量的更改操作,比如更改字段,添加或删除索引等等,我们把这些操作放到sql语句中,然后登陆mysql,通

由于经常对mysql数据库进行大量的更改操作,比如更改字段,添加或删除索引等等,我们把这些操作放到sql语句中,然后登陆mysql,,通过source执行该sql文件,为了做好相关记录,方便以后的工作中进行核对查询,将MySQL中sql运行结果保存到文件,类似Oracle sqlplus中利用spool的功能,方法大致如下,仅供参考:

1、登陆mysql之后
mysql> \T mysql_result.log
Logging to file 'mysql_result.log'
或者
mysql> tee mysql_result.log
Logging to file 'mysql_result.log'

2、[root@ ~]# mysql --tee=mysql_result.log

3、关闭mysql,然后修改mysql的配置文件中[client]选项段,添加以下内容(tee = /tmp/mysql_result.log)
例如:
[root@ ~]# vim /usr/local/mysql/etc/my.cnf
[client]
tee             = /tmp/mysql_result.log

以下是我的操作详细记录:
[root@ ~]# mysql -V
mysql  Ver 14.14 Distrib 5.1.45, for pc-linux-gnu (i686) using readline 5.1
[root@ ~]# mysql --help | grep tee
  --tee=name          Append everything into outfile. See interactive help (\h)
                      --disable-tee. This option is disabled by default.
  --no-tee            Disable outfile. See interactive help (\h) also. WARNING:
                      Option deprecated; use --disable-tee instead.
[root@ ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

通义万相
通义万相

通义万相,一个不断进化的AI艺术创作大模型

通义万相 596
查看详情 通义万相

mysql> \h

For information about MySQL products and services, visit:
  
For developer information, including the MySQL Reference Manual, visit:
  
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号