如何將 mytop 的輸出寫入文件

如何將 mytop 的輸出寫入文件

我們的應用程式使用一個非常繁忙的 MySQL 資料庫,有大量的讀取,有時我不想查看 MySQL 日誌文件,我只想查看 mytop 最後 5 分鐘的輸出。如何將 mytop 的輸出寫入檔案?

鑑於“mytop -u root --prompt > database.load”不起作用?

更新 我使用 --prompt 而不是帶有 -b 標誌的 -p ,它不斷拋出異常。所以解決方案就是這樣做mytop -u root -p password > database.load

答案1

您可以使用-bmytop 中的選項。從手冊頁:

   -b or --batch or --batchmode
       In batch mode, mytop runs only once, does not clear the screen, and places no limit on the number of lines it will
       print. This is suitable for running periodically (perhaps from cron) to capture the information into a file for later
       viewing. You might use batch mode in a CGI script to occasionally display your MySQL server status on the web.

       Default: unset.

答案2

像這樣:

mytop -b > /tmp/mytop.log

相關內容