MySQL不像Oracle會在源碼中植入大量的調試入口,最近忽然要調試一下MySQL的SQL執行過程,因而上官方查了一下,發現只有一個叫作Query Log的機制。當開關被打開以後,全部執行的SQL Statement都會被記錄下來,很是詳細,基本可以達到調試的目的。這是官方給出的Query Log功能描述:html
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.mysql
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.)sql
打開MySQL的Query Log的方式有兩個:數據庫
在版本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有關的參數性能優化
回想起來仍是Oracle膽子比較大,竟然直接把debug代碼留在Release中,使得在運行時獲得最大程度的指導錯誤調試和性能優化。現現在Oracle已經經過收購Sun擁有了MySQL,不知道這個開源免費的數據庫從此會如何發展下去。性能