MySQL error log和bin log
1.Error log
記錄DB啟動,執行,停止時嚴重錯誤
可用—log-error=file_name 選項指定mysqld報錯錯誤檔案的位置,如果沒有給定file_name值,使用:hostname.err 預設在引數DATADIR指定的目錄中
2. BIN log
二進位制記錄所有DDL,DML,但不包含查詢的語句,描述了資料的更改過程。災難時起著其重要作用
--log-bin如果沒有給出路徑,就寫在DATADIR
開啟bin log: log_bin
mysql> show variables like '%bin%';
+-----------------------------------------+----------------------+
| Variable_name | Value |
+-----------------------------------------+----------------------+
| binlog_format | STATEMENT |
| log_bin | OFF |
+-----------------------------------------+----------------------+
修改引數檔案D:\ProgramData\MySQL\MySQL Server 5.6\my.ini
log-bin=mysql-bin.log
重啟mysql
注意:在5.7.16 Linux 上有遇到
· In MySQL 5.7.3 and later, if you specify this option without also specifying a --server-id, the server is not allowed to start. (Bug #11763963, Bug #56739)
2016-11-02T02:40:05.342650Z 0 [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server start-up parameters documentation
需要設定server-id:
[mysqld]
log-bin=/data/mysql/mysql-bin.log
server-id=1
檢視bin log列表
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 120 |
+------------------+-----------+
1 row in set (0.00 sec)
檢視第一個bin log 內容
mysql> show binlog events ;
+------------------+-----+-------------+-----------+-------------+---------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info
|
+------------------+-----+-------------+-----------+-------------+---------------------------------------+
| mysql-bin.000001 | 4 | Format_desc | 1 | 120 | Server ver: 5.6.10-log, Binlog ver: 4 |
+------------------+-----+-------------+-----------+-------------+---------------------------------------+
1 row in set (0.00 sec)
檢視指定bin log內容
show binlog events in 'mysql-bin.000006';
檢視當前bin log是多少
show master status
binlog_format
1> STATEMENT
MySQL 5.1之前只有這種方式,日誌記錄都是statement
優點:日誌少,對I/O影響小
缺點:在某些情況下會導致master-slave中的資料不一致(如sleep()函式, last_insert_id(),以及user-defined functions(udf)等會出現問題)
2> ROW
MySQL 5.1.11後出現,每行變更記錄到日誌中
優點:每行變化都記錄,不會某些情況下無法複製的情況
缺點:日誌大,I/O影響大
3> MIXED
混合STATEMENT和ROW,預設採用STATEMENT,特殊情況下採用ROW:
NDB,客戶端使用臨時表,客戶端採用了不確定函式如current_user()
注:可在global和session 級修改binlog_format引數
set binlog_format=MIXED ;
set global binlog_format=MIXED ;
mysqlbinlog
讀取binlog
D:\ProgramData\MySQL\MySQL Server 5.6\data>mysqlbinlog mysql-bin.000001
如日誌是ROW,可加上-v –vv引數進行讀取
Binlog刪除
1> reset master
刪除所有binlog
2> purge master logs to 'mysql-bin.000002'
將000002前的刪除
3> purge master logs before '2016-10-21 15:00:00';
將時間前的刪除
4> expire_logs_days
set expire_logs_days=7
flush logs
手動重新整理log
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25583515/viewspace-2151830/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL的Redo log 以及Bin logMySql
- 【Mysql】三大日誌 redo log、bin log、undo logMySql
- Mysql系統變數中 log_error_services | log_filter_internal; log_sink_internal 和 log_error_verbosity | 2 解釋MySql變數ErrorFilter
- MySQL Undo Log和Redo Log介紹MySql
- MySQL中的redo log和undo logMySql
- MySQL的general_log和slow_logMySql
- MySQL [ERROR] Slave I/O: Found a Gtid_log_event or Previous_gtids_log_eventMySqlError
- 隨筆:MYSQL_BIN_LOG::COND_done 是什麼MySql
- 基於bin-log&position搭建主從架構MySQL架構MySql
- 雲伺服器mysql定期清理bin-log檔案伺服器MySql
- 2、MySQL錯誤日誌(Error Log)詳解MySqlError
- 深入理解MySQL系列之redo log、undo log和binlogMySql
- undo log和redo log
- MySQL Binary LogMySql
- MySQL中的redo log和checkpointMySql
- 基於Redo Log和Undo Log的MySQL崩潰恢復流程MySql
- mysql之 redo logMySql
- Error: The directory named as part of the path ./log/supervisord.log does not exist解決方案Error
- 必須瞭解的mysql三大日誌-binlog、redo log和undo logMySql
- MySQL通過bin log日誌恢復資料|手撕MySQL|對線面試官MySql面試
- MySQL學習之change buffer 和 redo logMySql
- Mysql三類log解析MySql
- 3000幀動畫圖解MySQL為什麼需要binlog、redo log和undo log動畫圖解MySql
- ORA-01511 error in renaming log/data files ORA-00261 log 4 of thread 1 is beingErrorthread
- mysql日誌:redo log、binlog、undo log 區別與作用MySql
- MySQL中redo log、undo log、binlog關係以及區別MySql
- MySQL案例09:Last_IO_Error: Got fatal error 1236 from master when reading data from binary logMySqlASTErrorGo
- wordpress 記錄php-error.log路徑PHPError
- ELK收集mysql_slow.logMySql
- MySQL:慢SQL(slow_log)MySql
- MySQL8.0:The General Query LogMySql
- MySQL redo log最佳化MySql
- MySQL重做日誌(redo log)MySql
- Tomcat 中 catalina.out、catalina.log、localhost.log 和 access_log 的區別Tomcatlocalhost
- 還不懂mysql的undo log和mvcc?算我輸!MySqlMVC
- 開啟 mysql 的 general_logMySql
- 談談MySQL bin log的寫入機制、以及線上的引數是如何配置的MySql
- exclude Log4j print Log