《Disney +》 迪士尼、Marvel、彼思、星球大戰…  「Indie World 2021.4.15」影片公開!發表內容統整在這裡!   師父的死與年齡增長系統運作的方式   狩獵解禁!《MONSTER HUNTER RISE》今日開賣!4月底更新的新增魔物大公開!   原神1.3版本更新:來海燈節一起歡度提瓦特的新年吧!   今天日開始『激戰任務2』的「3週年大感謝祭」!「ν鋼彈」和「沙薩比」終於參戰!!   「Evo 社群系列賽」 PlayStation 4 Tournaments比賽開跑!   是那個擁有烏黑亮麗直髮的男人!「村田」確定參戰「鬼滅之刃 火神血風譚」!   hololive的元宇宙虛擬世界!沙盒類遊戲「Holo Earth」最新情報公開! 

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

隨機商業新聞