mysql日誌管理

來源:互聯網
上載者:User

標籤:設定檔   伺服器   資料庫   mysql   二進位   

                  Mysql日誌

錯誤記錄檔:記錄mysql伺服器啟動,關閉以及運行錯誤等資訊

二進位日誌:已二進位檔案的方式記錄資料庫中除select以外的所有操作(最重要的日誌)

查詢日誌:記錄查詢的資訊

慢查詢日誌:記錄執行時間超過指定時間的操作

中繼日誌:備庫將主庫的日誌複製到自己的中繼日誌中(主從複製的時候用到)

通用日誌:審計那個帳號,在哪個時間做了哪些事情

交易記錄或稱redo日誌:記錄innodb事務相關如事務執行時間,檢查點

 

 

二進位日誌bin-log

啟用

Vim /etc/my.cnf   //編輯mysql主設定檔

[mysqld]

Log-bin[=dir\[filename]]   //添加這一行就可以了

 

Service mysqld  restart   //重啟mysq進程

 

 

Mysql > set sql_log_bin=0;  //停止

Mysql > set sql_log_bin=0;  //啟用   只針對當前會話

 

 

 

查看日誌

查看全部:

#Mysqlbinlog mysql.000002

 

按時間查看

#Mysqlbinlog mysql.000002  --start-datetime=”2012-12-05 10:02:56”

#Mysqlbinlog mysql.000002  --stop-datetime=”2012-12-05 11:02:56”

#Mysqlbinlog mysql.000002  --start-datetime=”2012-12-05 10:02:56”  --stop-datetime=”2012-12-05 11:02:56”

 

按位元組數查看

#Mysqlbinlog mysql.000002  --start-position=260

#Mysqlbinlog mysql.000002  --stop-position=260

#Mysqlbinlog mysql.000002  --start-position=260  --stop-position=930

 

截斷bin-log (產生新的bin-log檔案)兩種方法

1)重啟mysql伺服器

2)#mysql -uroot -p123-e ‘flush logs’

 

刪除bin-log檔案

#mysql -uroot -p123 -e ‘reset master’

 

 

通用查詢日誌

啟用

Vim /etc/my.cnf   //編輯mysql主設定檔

[mysqld]

Log[=dir\[filename]]   //添加這一行就可以了

 

Service mysqld  restart   //重啟mysq進程

 

慢查詢日誌

啟用

Vim /etc/my.cnf   //編輯mysql主設定檔

[mysqld]

Log-slow-queries[=dir\[filename]]

Long_query_time=n  //添加這兩行就可以了

 

Service mysqld  restart   //重啟mysq進程

 

查看慢查詢日誌

測試:benchmark(count,expr)

Select benchmark(5000000000,2*3);   //執行5000000000次2*3

 

 

總結:mysql日誌管理,二進位日誌最為重要,使用它可以對資料庫基於時間點的恢複,同時二進位記錄檔是mysql主從複製的關鍵

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


本文出自 “快樂學習” 部落格,請務必保留此出處http://983865387.blog.51cto.com/9838888/1917423

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.