- 查看系統版本
[root@Lime-CentOS ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core) - 查看MySQL版本
root@Lime-CentOS ~]# mysql --help | grep Distrib mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper - 檢查是否開啟binlog
mysql> show variables like '%log_bin%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin | OFF | | log_bin_basename | | | log_bin_index | | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | | sql_log_bin | ON | +---------------------------------+-------+ 6 rows in set (0.00 sec) - log-bin開啟binlog
[root@Lime-CentOS ~]# vim /etc/my.cnf [mysqld] # binlog config # 開啟 Binlog 并寫明存放日志的位置;默認使用的設定是“log-bin=mysql-bin”,這樣日志是存放在默認的位置上的,一般是放在data目錄中, log-bin=mysql-bin # 指定一個集群內的 MySQL 服務器 ID,如果做資料庫集群那么必須全域唯一,一般來說不推薦 指定 server-id 等于 1, server-id=1 # 設定Bin-log日志模式, binlog_format=ROW - 重啟MySQL服務
root@Lime-CentOS ~]# sudo systemctl restart mysqld - 查看有哪些binlog
mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 177 | | mysql-bin.000002 | 154 | +------------------+-----------+ 2 rows in set (0.00 sec) mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 177 | | mysql-bin.000002 | 154 | +------------------+-----------+ 2 rows in set (0.00 sec) - 查看第一個binlog的內容
mysql> show binlog events; +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | mysql-bin.000001 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.32-log, Binlog ver: 4 | | mysql-bin.000001 | 123 | Previous_gtids | 1 | 154 | | | mysql-bin.000001 | 154 | Stop | 1 | 177 | | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ 3 rows in set (0.00 sec) - 指定查看具體的binlog日志的內容
mysql> show binlog events in 'mysql-bin.000002'; +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | mysql-bin.000002 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.32-log, Binlog ver: 4 | | mysql-bin.000002 | 123 | Previous_gtids | 1 | 154 | | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ 2 rows in set (0.00 sec) - 查看當前正在寫入的binlog日志檔案
mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000002 | 154 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) - 重新開始一個日志檔案
mysql> flush logs; Query OK, 0 rows affected (0.01 sec) - 在row模式下..開啟該引數,將把sql陳述句列印到binlog日志里面.默認是0(off);
mysql> select @@binlog_rows_query_log_events; +--------------------------------+ | @@binlog_rows_query_log_events | +--------------------------------+ | 0 | +--------------------------------+ 1 row in set (0.00 sec) mysql> set binlog_rows_query_log_events = 1; Query OK, 0 rows affected (0.00 sec) mysql> select @@binlog_rows_query_log_events; +--------------------------------+ | @@binlog_rows_query_log_events | +--------------------------------+ | 1 | +--------------------------------+ 1 row in set (0.00 sec) - binlog_row_image
-- 默認為full. -- 在binlog為row格式下, -- full將記錄update前后所有欄位的值, -- minimal時,只記錄更改欄位的值和where欄位的值, -- noblob時,記錄除了blob和text的所有欄位的值,如果update的blob或text欄位,也只記錄該欄位更改后的值,更改前的不記錄; select @@binlog_row_image; set binlog_row_image='minimal'; - 查看binlog_cache_use、binlog_cache_disk_use的狀態
-- 當使用事務的表存盤引擎時,所有未提交(uncommitted)的二進制日志會被記錄到一個快取中去, -- 等該事物提交(committed)時直接將緩沖中的二進制日志寫入二進制日志檔案, -- 而該緩沖的大小由binlog_cache_size決定,默認大小為32K,此外, -- binlog_cache_size是基于會話(session)的,也就是說,當一個執行緒開始一個事務時, -- MySQL會自動分配一個大小為binlog_cache_size的快取,因此該值的設定需要相當小心, -- 不能設定過大,當一個事務的記錄大于設定的binlog_cache_size時, -- MySQL會把緩沖中的日志寫入一個臨時檔案中,因此該值又不能設得太小, -- 通過SHOW GLOBAL STATUS 命令查看binlog_cache_use、binlog_cache_disk_use的狀態, -- 可以判斷當前binlog_cache_size的設定是否合適, -- binlog_cache_use記錄了使用緩沖寫二進制日志的次數, -- binlog_cache_disk_use記錄了使用臨時檔案寫二進制日志的次數, mysql> SHOW GLOBAL STATUS\G *************************** 3. row *************************** Variable_name: Binlog_cache_disk_use Value: 0 *************************** 4. row *************************** Variable_name: Binlog_cache_use Value: 0 - 洗掉日志索引檔案中記錄的所有binlog檔案,創建一個新的日志檔案,起始值從000001開始
mysql> reset master; Query OK, 0 rows affected (0.01 sec) - sync_binlog = 1
- innodb_support_xa = 1
- binlog-do-db
- binlog-ignore-db
- log-slave-update
- mysqlbinlog
- 根據備份的方法
- 熱備份
- MVCC
- ibbackup
- xtrabackup
- mysqldump --single-transaction
- 冷備份
- frm檔案
- 共享表空間
- 獨立表空間檔案
- 重做日志檔案
- 溫備份
- 熱備份
- 按照備份后檔案的內容
- 邏輯備份
- 裸檔案備份
- 按照備份資料庫的內容
- 完全備份
- 增量備份
- 日志備份
- REDO
- UNDO
- 啦啦啦
- 啦啦啦
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/250766.html
標籤:其他
上一篇:MyBatis 查詢資料時屬性中多對一的處理(多條資料對應一條資料)
下一篇:帶引數的存盤程序報錯
