MySQL tee實現Oracle Spool

神諭丶發表於2015-09-08
mysql客戶端中,輸入help可以檢視到一個命令:
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
該命令可以通過tee指令來實現類似oracle db中的spool一樣的功能。

使用起來很簡單:

開啟tee的方法:

可以直接在客戶端啟動的時候加上--tee引數,後接輸出路徑,當然也可以直接加輸出檔名,此時該檔案將會寫在當前目錄下。
[op@sAno1y ~]$ mysql -uroot -p --tee=/tmp/test.log
Logging to file '/tmp/test.log'
Enter password: 

也可以在mysql client中新增,根據help的提示,很輕易可以知道:

可以直接輸入 tee outfile_name來實現寫入。
mysql> tee /tmp/test.log

檢視/tmp/test.log可以看到記錄:



當然也可以通過\T來實現

mysql> \T /tmp/test.log
Logging to file '/tmp/test.log'


關閉tee的方法:
輸入\t即可,此時可以看到結束輸出的提示。
mysql> \t
Outfile disabled.
也可以用notee來實現:
mysql> notee
Outfile disabled.

作者公眾號(持續更新)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29773961/viewspace-1794697/,如需轉載,請註明出處,否則將追究法律責任。

相關文章