如何記錄MySQL執行過的SQL語句

來源:互聯網
上載者:User

標籤:http   os   ar   for   檔案   art   log   ad   ef   

很多時候,我們需要知道 MySQL 執行過哪些 SQL 陳述式,比如 MySQL 被注入後,需要知道造成什麼傷害等等。只要有 SQL 陳述式的記錄,就能知道情況並作出對策。伺服器是可以開啟 MySQL 的 SQL 陳述式記錄功能,從而就能間接地檢測到用戶端程式的行為。淶水縣梁以紙業

開啟方法很簡單:編輯/etc/my.cnf檔案,在[mysqld]節下面添加:log=/var/lib/mysql/sql_row.log行(日誌的路徑自己根據需要定義)。

[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Default to using old password format for compatibility with mysql 3.x# clients (those using the mysqlclient10 compatibility package).old_passwords=1log=/var/lib/mysql/sql_row.log# Disabling symbolic-links is recommended to prevent assorted security risks;# to do so, uncomment this line:# symbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

修改完畢後,記得重啟 MySQL:

service mysql restart# 或者/etc/init.d/mysqld stop/etc/init.d/mysqld start

現在你去 /var/lib/mysql/ 路徑下的 sql_row.log 檔案應該是能夠看到 MySQL 什麼時候執行了哪些程式了。

如何記錄MySQL執行過的SQL語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.