問題描述
我可以在我的 mysql 數據庫上打開審計日志嗎?
Is it possible for me to turn on audit logging on my mysql database?
我基本上想監控所有查詢一個小時,并將日志轉儲到文件中.
I basically want to monitor all queries for an hour, and dump the log to a file.
推薦答案
UPDATE: NO LONGER VALID FOR MYSQL 5.6+
UPDATE: NO LONGER VALID FOR MYSQL 5.6+
使用 --log 選項啟動 mysql:
Start mysql with the --log option:
mysqld --log=log_file_name
或將以下內容放入您的 my.cnf
文件中:
or place the following in your my.cnf
file:
log = log_file_name
任何一個都會將所有查詢記錄到 log_file_name.
Either one will log all queries to log_file_name.
您還可以使用 --log-slow-queries
選項而不是 --log
選項僅記錄慢查詢.默認情況下,需要 10 秒或更長時間的查詢被認為是緩慢的,您可以通過將 long_query_time
設置為查詢在被記錄之前必須執行的秒數來更改這一點.
You can also log only slow queries using the --log-slow-queries
option instead of --log
. By default, queries that take 10 seconds or longer are considered slow, you can change this by setting long_query_time
to the number of seconds a query must take to execute before being logged.
這篇關于記錄mysql中的所有查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!