《Disney +》 迪士尼、Marvel、彼思、星球大戰…  跟隨最新《Solar Ash》實機遊玩影片進入極空之旅探險   「年末優惠」進駐PlayStation Store   hololive 官方網店hololive production OFFICIAL SHOP正式開業   這個夏天一起來種稻吧!《天穗之咲稻姬》首次特惠開跑!   魔物獵人系列最新作「魔物獵人 崛起」公開最新情報!體驗版將再度開放!   塑造與再現:《地平線 西域禁地》中氣勢凜凜的機器   龍族拼圖P&D和「UNDONE」合作推出10週年紀念錶!   Razer宣布將推出可同時控制複數裝置燈光效果的「Razer Chroma Addressable RGB Controller」! 

MySQL Log 所有 SQL 語法

商業

MySQL 最常使用的是 Log Slow Query,但是除了 Slow Query 外,還有情況是要抓不知哪來的 SQL 語法,或者要查是哪些語法一起來造成 Lock 等等的問題,所以想要知道 MySQL 到底都接收到哪些 SQL Query?

要怎麼將所有的 SQL 語法都記錄下來呢?

MySQL Log 所有 SQL 語法

MySQL 想要將所有進來的 SQL 語法記錄下來,依照 MySQL 的版本不同,有兩種不同的寫法。

MySQL 5.1.29 版之前的做法 (不含 5.1.29)

[mysqld]
log=/path/to/filename.log

MySQL 5.1.29 版以後的做法 (含 5.1.29、8.0 都是此寫法)

[mysqld]
general_log = on
general_log_file=/path/to/filename.log

修改完成後,restart mysql 才能生效

MySQL 即時關閉 Log

  • mysql> SET GLOBAL general_log = 'OFF';

MySQL 即時打開 Log

  • mysql> SET GLOBAL general_log = 'ON';

MySQL 8.0 文件說明:MySQL 8.0 Reference Manual :: 5.4.3 The General Query Log

此篇有紀錄版本差異:MySQL 5.1 Reference Manual :: 5.2.3 The General Query Log

  • Before 5.1.6, the general query log destination is always a file. To enable the log, start mysqld with the --log[=file_name] or -l [file_name] option.
  • As of MySQL 5.1.6, the destination can be a file or a table, or both. Start mysqld with the --log[=file_name] or -l [file_name] option to enable the general query log, and optionally use --log-output to specify the log destination (as described in Section 5.2.1, “Selecting General Query and Slow Query Log Output Destinations”).
  • As of MySQL 5.1.12, as an alternative to --log or -l, use --general_log[={0|1}] to specify the initial general query log state. In this case, the default general query log file name is used. With no argument or an argument of 1, --general_log enables the log. With an argument of 0, this option disables the log.
Tsung

隨機商業新聞

Addidas