問(wèn)題描述
我可以在我的 mysql 數(shù)據(jù)庫(kù)上打開(kāi)審計(jì)日志嗎?
Is it possible for me to turn on audit logging on my mysql database?
我基本上想監(jiān)控所有查詢(xún)一個(gè)小時(shí),并將日志轉(zhuǎn)儲(chǔ)到文件中.
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 選項(xiàng)啟動(dòng) mysql:
Start mysql with the --log option:
mysqld --log=log_file_name
或?qū)⒁韵聝?nèi)容放入您的 my.cnf
文件中:
or place the following in your my.cnf
file:
log = log_file_name
任何一個(gè)都會(huì)將所有查詢(xún)記錄到 log_file_name.
Either one will log all queries to log_file_name.
您還可以使用 --log-slow-queries
選項(xiàng)而不是 --log
選項(xiàng)僅記錄慢查詢(xún).默認(rèn)情況下,需要 10 秒或更長(zhǎng)時(shí)間的查詢(xún)被認(rèn)為是緩慢的,您可以通過(guò)將 long_query_time
設(shè)置為查詢(xún)?cè)诒挥涗浿氨仨殘?zhí)行的秒數(shù)來(lái)更改這一點(diǎn).
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.
這篇關(guān)于記錄mysql中的所有查詢(xún)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!