MySQL Query Log

來源:互聯網
上載者:User

MySQL Query Log

MySQL不像Oracle會在源碼中植入大量的調試入口,最近突然要調試一下MySQL的SQL執行過程,於是上官方查了一下,發現只有一個叫做Query Log的機制。當開關被開啟之後,所有執行的SQL Statement都會被記錄下來,非常詳細,基本能夠達到調試的目的。這是官方給出的Query Log功能描述:

The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.

mysqld writes statements to the query log in the order that it receives them, which might differ from the order in which they are executed. This logging order contrasts to the binary log, for which statements are written after they are executed but before any locks are released. (Also, the query log contains all statements, whereas the binary log does not contain statements that only select data.)

 

 

開啟MySQL的Query Log的方式有兩個:

1.       在啟動MySQL的時候加入以下啟動參數:”--log[=file_name] or -l [file_name] option”

在版本5.1.6之前,記錄下來的Query Log只能儲存在MySQL內部的一張table中,而在5.1.6版本之後,Query Log既可以儲存在table也可以儲存在File中,資料庫中會有一個參數叫做general_log,值為0或1,代表了Query Log的啟動開關,我們可以在MySQL中執行”show variables like %log%” 可以看到所有跟log有關的參數

 

2.         另外一種方式就是在MySQL的設定檔my.ini末尾加上一行”log=D:/temp_sql.log”,這種方式似乎沒有在官方文檔中找到描述,但是卻非常實用。

 

回想起來還是Oracle膽子比較大,居然直接把debug代碼留在Release中,使得在運行時得到最大程度的指導錯誤調試和效能最佳化。現如今Oracle已經通過收購Sun擁有了MySQL,不知道這個開源免費的資料庫今後會如何發展下去。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.