日誌文件記錄了MySQL數據庫的各類類型的活動,MySQL數據庫中常見的日誌文件有 查詢日誌,慢查詢日誌,錯誤日誌,二進制日誌,中繼日誌 ,事務日誌。mysql
修改配置或者想要使配置永久生效需將內容寫入配置文件中:/etc/my.cnf.d/server.cnfgit
查詢日誌在mysql中稱爲general log(通用日誌),查詢日誌記錄了數據庫執行的命令,無論這些語句是否正確,都會被記錄。因爲數據庫操做命令有可能很是多並且執行比較頻繁,因此開啓了查詢日誌之後,數據庫可能須要不停的寫入查詢日誌,這樣會增大服務器的IO壓力,增長不少系統開銷,影響數據庫的性能,因此默認狀況下是關閉的,也不建議開啓。正則表達式
存儲查詢日誌的方式:sql
方式1:將查詢日誌存放於指定的日誌文件中;數據庫
方式2:將查詢日誌存放於mysql.general_log表中;vim
方式3:將查詢日誌同時存放於指定的日誌文件與mysql庫的general_log表中。緩存
一、查看查詢日誌的相關參數安全
MariaDB [mysql]> show global variables like '%gen%log%'; +------------------+----------+ | Variable_name | Value | +------------------+----------+ | general_log | OFF | | general_log_file | ren7.log | +------------------+----------+ 2 rows in set (0.00 sec) MariaDB [mysql]> show variables where variable_name like '%general_log%' or variable_name='log_output'; +------------------+----------+ | Variable_name | Value | +------------------+----------+ | general_log | OFF | | general_log_file | ren7.log | | log_output | FILE | +------------------+----------+ 3 rows in set (0.00 sec)
二、查詢日誌變量詳解服務器
1 general_log: 指定是否開啓查詢日誌(ON表示開啓,OFF表示未開啓,默認OFF) 2 general_log_file: 當log_output設置爲「FILE」時,指定將查詢日誌保存成哪一個文件、叫什麼名,默認與主機名相同,通常位於/var/lib/mysql目錄下 3 log_output: 指定將記錄到的查詢保存到什麼位置(「NONE」、「FILE」、「TABLE」、「FILE,TABLE」) 4 file: 保存成一個文件 5 table: 保存成一張表 6 none: 不記錄
慢查詢日誌用來記錄響應時間超過閾值的SQL語句,因此咱們能夠設置一個閾值,將運行時間超過該值的全部SQL語句都記錄到慢查詢日誌文件中。該閾值能夠經過參數 slow_launch_time
來設置,默認爲2秒。網絡
一、查看慢查詢日誌的變量
MariaDB [mysql]> show global variables like '%slow%'; +---------------------------+--------------------------------------------------------------------------------------------------------------+ | Variable_name | Value | +---------------------------+--------------------------------------------------------------------------------------------------------------+ | log_slow_admin_statements | ON | | log_slow_filter | admin,filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk | | log_slow_rate_limit | 1 | | log_slow_slave_statements | ON | | log_slow_verbosity | | | slow_launch_time | 2 | | slow_query_log | OFF | | slow_query_log_file | ren7-slow.log | +---------------------------+--------------------------------------------------------------------------------------------------------------+ 8 rows in set (0.00 sec)
二、變量詳解
1 slow_query_log = OFF|ON (0|1) #開啓慢查詢日誌 2 slow_query_log_file = LOCALHOST-SLOW.log #慢查詢日誌的文件路徑 3 long_query_time #慢查詢時長;默認是10s 4 log_slow_rate_limit #若是要記錄的慢查詢日誌很是多的話,會按照速率來記錄,默認1秒記錄一個 5 log_slow_verbosity=full | query_plan #記錄的詳細級別 6 log_output #指定將記錄到的查詢保存到什麼位置
三、開啓慢查詢日誌及測試
MariaDB [(none)]> set global slow_query_log=on; #當前會話不生效,需從新鏈接數據庫 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> select @@global.slow_query_log; +-------------------------+ | @@global.slow_query_log | +-------------------------+ | 1 | +-------------------------+ 1 row in set (0.00 sec) MariaDB [(none)]> select sleep(15); #測試4次 +-----------+ | sleep(15) | +-----------+ | 0 | +-----------+ 1 row in set (15.00 sec) [root@ren7 mysql]# tailf /var/lib/mysql/ren7-slow.log #查看慢查詢日誌的文件(默認保存類型是FILE) # Time: 190907 15:47:18 # User@Host: root[root] @ localhost [] # Thread_id: 10 Schema: QC_hit: No # Query_time: 15.008583 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0 # Rows_affected: 0 SET timestamp=1567842438; select sleep(15); MariaDB [ren]> show global status like '%slow_queries%'; #查看一共記錄了多少條慢查詢語句 +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Slow_queries | 4 | +---------------+-------+ 1 row in set (0.00 sec)
四、mysqldumpslow命令
mysqldumpslow是mysql自帶的慢查詢日誌統計分析工具,能夠對慢查詢日誌進行排序、查找、統計(只有咱們將log_output的值設置爲「FILE」或者「FILE,TABLE」時,mysqldumpslow才能夠用)
(1)使用
[root@ren7 ~]# mysqldumpslow -s t /var/lib/mysql/ren7-slow.log Reading mysql slow query log from /var/lib/mysql/ren7-slow.log Count: 4 Time=15.01s (60s) Lock=0.00s (0s) Rows_sent=1.0 (4), Rows_examined=0.0 (0), Rows_affected=0.0 (0), root[root]@localhost select sleep(N)
(2)參數說明
[root@ren7 ~]# mysqldumpslow --help Usage: mysqldumpslow [ OPTS... ] [ LOGS... ] Parse and summarize the MySQL slow query log. Options are --verbose verbose --debug debug --help write this text to standard output -v verbose -d debug -s ORDER what to sort by (aa, ae, al, ar, at, a, c, e, l, r, t), 'at' is default aa: average rows affected ae: aggregated rows examined al: average lock time(平均鎖定時間) ar: average rows sent(平均返回記錄數) at: average query time(平均執行時間) a: rows affected c: count(執行計數) e: rows examined l: lock time(鎖定時間) r: rows sent(返回記錄) t: query time(執行時間) -r reverse the sort order (largest last instead of first) -t NUM just show the top n queries(指定只查看多少條統計信息) -a don't abstract all numbers to N and strings to 'S' -n NUM abstract numbers with at least n digits within names -g PATTERN grep: only consider stmts that include this string(正則表達式) -h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard), default is '*', i.e. match all -i NAME name of server instance (if using mysql.server startup script) -l don't subtract lock time from total time
主要記錄:(很重要的信息日誌文件)
(1)mysqld啓動和關閉過程當中輸出的事件信息
(2)mysqld運行中產生的錯誤信息
(3)event scheduler 運行一個event時產生的日誌信息
(4)在主從複製架構中的從服務器IO複製線程時產生的信息
一、查看參數
MariaDB [mysql]> show variables like '%log_error%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_error | | +---------------+-------+ 1 row in set (0.00 sec) MariaDB [mysql]> show variables like '%log_warnings%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_warnings | 2 | +---------------+-------+ 1 row in set (0.01 sec)
二、參數詳解
1 log_error = /var/log/mysql_error.log #指定錯誤日誌的輸出位置 2 log_warnings 爲0, 表示不記錄告警信息。 3 log_warnings 爲1, 表示告警信息寫入錯誤日誌。 4 log_warnings 大於1, 表示各種告警信息,例若有關網絡故障的信息和從新鏈接信息寫入錯誤日誌。(默認爲2)
在mysql中二進制日誌爲binlog,它記錄了對數據庫執行更改的全部操做,可是不包括 select
和 show
這類操做,由於這類操做對數據自己並無修改,若是你還想記錄select和show操做,那隻能使用查詢日誌了,而不是二進制日誌。(增刪改的SQL語句)
二進制還包括了執行數據庫更改操做的時間和執行時間等信息,它主要用於時間點恢復(備份恢復)以及主從複製結構
point-in-time
的恢復一、查看變量
MariaDB [mysql]> show global variables like '%bin%'; +-----------------------------------------+--------------------------------+ | Variable_name | Value | +-----------------------------------------+--------------------------------+ | binlog_annotate_row_events | ON | | binlog_cache_size | 32768 | | binlog_checksum | CRC32 | | binlog_commit_wait_count | 0 | | binlog_commit_wait_usec | 100000 | | binlog_direct_non_transactional_updates | OFF | | binlog_format | MIXED | | binlog_optimize_thread_scheduling | ON | | binlog_row_image | FULL | | binlog_stmt_cache_size | 32768 | | encrypt_binlog | OFF | | gtid_binlog_pos | 0-1-1 | | gtid_binlog_state | 0-1-1 | | innodb_locks_unsafe_for_binlog | OFF | | log_bin | ON | | log_bin_basename | /var/lib/mysql/mysql-bin | | log_bin_compress | OFF | | log_bin_compress_min_len | 256 | | log_bin_index | /var/lib/mysql/mysql-bin.index | | log_bin_trust_function_creators | OFF | | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | | read_binlog_speed_limit | 0 | | sql_log_bin | ON | | sync_binlog | 0 | | wsrep_forced_binlog_format | NONE | +-----------------------------------------+--------------------------------+ 27 rows in set (0.00 sec)
二、變量詳解
二進制日誌文件的構成:
(1)日誌文件:mysql-bin.xxxxxx,二進制格式
(2)索引文件:mysql-bin,index,索引文件(十進制文件)
log_bin = LOG_NAME: (只讀變量)只能經過修改配置文件來指定是否啓用二進制日誌(全局的)
#my.cnf配置文件中沒有log_bin的配置,表示未開啓二進制日誌,若是存在log_bin的配置,則表示開啓了二進制日誌,同時,二進制日誌文件的名稱將會以log_bin對應的值爲文件名前綴,文件默認位置在/var/lib/mysql/下,二進制日誌文件的後綴名會進行自動編號,每第二天志滾動後,後綴名編號自動加1. log_bin_basename = /var/lib/mysql/mysql-bin: 指定二進制日誌的文件的基名 log_bin_index = /var/lib/mysql/mysql-bin.index:指定二進制日誌文件的索引文件 binlog_format = STATEMENT|ROW|MIXED: 指定基於哪一種方式進行記錄
STATEMENT: 基於「語句」記錄
ROW: 基於「行」記錄
MIXED: 讓系統自行斷定該基於哪一種方式記錄
sync_binlog = 1|0: 設定是否啓動二進制日誌同步功能 -->每次提交事務,會將緩存中的內存刷新到二進制日誌文件中。 -->默認每一個sql語句是一個事務,並且默認事務會自動提交,因此,默認的性能不好
-->此值爲0時,表示當事務提交後,不會當即將內存中的binlog刷新到磁盤中;安全性最差,性能最高
-->此值爲1時,表示每一次事務提交後,都會當即將內存中的二進制文件同步到磁盤中;安全性最高,性能最差
-->還能設置爲N,當設置爲3時,表示每3次事務提交後,將binlog從內存刷寫到磁盤一次,值設置的越大,有可能丟失的日誌數據越多,但性能會越好
max_binlog_size = SIZE: 指定二進制日誌文件的上限,超過上限會滾動,以字節爲單位(默認爲1G,爲1073741824B) max_binlog_cache_size = SIZE: 指定二進制日誌緩存空間大小,空間被填滿,會自動滾動 sql_log_off = on|off: 是否將通常的查詢操做記錄到二進制日誌中 sql_log_bin = ON |OFF: 指定是否啓用二進制日誌(會話級別) log_bin_trust_function_creators = on|off: 指定是否容許建立可能致使不安全的函數
三、查看二進制日誌文件列表及事件
SHOW {BINARY | MASTER} LOGS
SHOW BINLOG EVENTS [IN 'log_name']
show master status;
--修改配置文件
[root@ren7 ~]# vim /etc/my.cnf.d/server.cnf ############################# [server] log_bin = mysql-binlog ##############################
--重啓服務 [root@ren7 ~]# systemctl restart mariadb [root@ren7 ~]# mysql -uroot -proot -D ren; --查看二進制日誌文件列表
MariaDB [ren]> show master logs; +---------------------+-----------+ | Log_name | File_size | +---------------------+-----------+ | mysql-binlog.000001 | 331 | +---------------------+-----------+ 1 row in set (0.00 sec) MariaDB [ren]> show binary logs; +---------------------+-----------+ | Log_name | File_size | +---------------------+-----------+ | mysql-binlog.000001 | 331 | +---------------------+-----------+ 1 row in set (0.00 sec) --查看當前正在使用的二進制日誌文件
MariaDB [ren]> show master status; +---------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +---------------------+----------+--------------+------------------+ | mysql-binlog.000001 | 331 | | | +---------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
--修改數據庫的文件 MariaDB [ren]> drop table test4; Query OK, 0 rows affected (0.00 sec) MariaDB [ren]> delete from test where name='李連杰'; Query OK, 1 row affected (0.00 sec) MariaDB [ren]> insert into test set name='漩渦鳴人'; Query OK, 1 row affected (0.01 sec) --再次查看二進制日誌文件 MariaDB [ren]> show master status; +---------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +---------------------+----------+--------------+------------------+ | mysql-binlog.000001 | 840 | | | +---------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
--查看二進制日誌文件中的事件(查看binlog內容)
MariaDB [ren]> show binlog events; MariaDB [ren]> show binlog events in 'mysql-binlog.000001'; +---------------------+-----+-------------------+-----------+-------------+---------------------------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +---------------------+-----+-------------------+-----------+-------------+---------------------------------------------------------+ | mysql-binlog.000001 | 4 | Format_desc | 1 | 256 | Server ver: 10.2.26-MariaDB-log, Binlog ver: 4 | | mysql-binlog.000001 | 256 | Gtid_list | 1 | 285 | [] | | mysql-binlog.000001 | 285 | Binlog_checkpoint | 1 | 331 | mysql-binlog.000001 | | mysql-binlog.000001 | 331 | Gtid | 1 | 373 | GTID 0-1-1 | | mysql-binlog.000001 | 373 | Query | 1 | 483 | use `ren`; DROP TABLE `test4` /* generated by server */ | | mysql-binlog.000001 | 483 | Gtid | 1 | 525 | BEGIN GTID 0-1-2 | | mysql-binlog.000001 | 525 | Query | 1 | 630 | use `ren`; delete from test where name='李連杰' | | mysql-binlog.000001 | 630 | Xid | 1 | 661 | COMMIT /* xid=22 */ | | mysql-binlog.000001 | 661 | Gtid | 1 | 703 | BEGIN GTID 0-1-3 | | mysql-binlog.000001 | 703 | Query | 1 | 809 | use `ren`; insert into test set name='漩渦鳴人' | | mysql-binlog.000001 | 809 | Xid | 1 | 840 | COMMIT /* xid=23 */ | +---------------------+-----+-------------------+-----------+-------------+---------------------------------------------------------+ 11 rows in set (0.00 sec) MariaDB [ren]> show binlog events in 'mysql-binlog.000001' from 256; +---------------------+-----+-------------------+-----------+-------------+---------------------------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +---------------------+-----+-------------------+-----------+-------------+---------------------------------------------------------+ | mysql-binlog.000001 | 256 | Gtid_list | 1 | 285 | [] | | mysql-binlog.000001 | 285 | Binlog_checkpoint | 1 | 331 | mysql-binlog.000001 | | mysql-binlog.000001 | 331 | Gtid | 1 | 373 | GTID 0-1-1 | | mysql-binlog.000001 | 373 | Query | 1 | 483 | use `ren`; DROP TABLE `test4` /* generated by server */ | | mysql-binlog.000001 | 483 | Gtid | 1 | 525 | BEGIN GTID 0-1-2 | | mysql-binlog.000001 | 525 | Query | 1 | 630 | use `ren`; delete from test where name='李連杰' | | mysql-binlog.000001 | 630 | Xid | 1 | 661 | COMMIT /* xid=22 */ | | mysql-binlog.000001 | 661 | Gtid | 1 | 703 | BEGIN GTID 0-1-3 | | mysql-binlog.000001 | 703 | Query | 1 | 809 | use `ren`; insert into test set name='漩渦鳴人' | | mysql-binlog.000001 | 809 | Xid | 1 | 840 | COMMIT /* xid=23 */ | +---------------------+-----+-------------------+-----------+-------------+---------------------------------------------------------+ 10 rows in set (0.00 sec) MariaDB [ren]> show binlog events in 'mysql-binlog.000001' limit 1,2; +---------------------+-----+-------------------+-----------+-------------+---------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +---------------------+-----+-------------------+-----------+-------------+---------------------+ | mysql-binlog.000001 | 256 | Gtid_list | 1 | 285 | [] | | mysql-binlog.000001 | 285 | Binlog_checkpoint | 1 | 331 | mysql-binlog.000001 | +---------------------+-----+-------------------+-----------+-------------+---------------------+ 2 rows in set (0.00 sec)
四、二進制日誌滾動
(1)flush logs;
(2)文件超出指定大小;
(3)重啓數據庫(service mariadb restart / systemctl restart mariadb)
五、查看二進制日誌文件(mysqlbinlog命令)
除了前面提到的能夠經過show binlog events命令在mysql中查看日誌內容,還能夠經過mysqlbinlog命令在文件系統下查看對應的二進制日誌文件。
[root@ren7 mysql]# pwd /var/lib/mysql [root@ren7 mysql]# mysqlbinlog mysql-binlog.000001 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #190907 17:15:09 server id 1 end_log_pos 256 CRC32 0x16b33f7c Start: binlog v 4, server v 10.2.26-MariaDB-log created 190907 17:15:09 at startup # Warning: this binlog is either in use or was not closed properly. ROLLBACK/*!*/; BINLOG ' HXVzXQ8BAAAA/AAAAAABAAABAAQAMTAuMi4yNi1NYXJpYURCLWxvZwAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAddXNdEzgNAAgAEgAEBAQEEgAA5AAEGggAAAAICAgCAAAACgoKAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAEEwQADQgICAoKCgF8P7MW '/*!*/; # at 256 #190907 17:15:09 server id 1 end_log_pos 285 CRC32 0x6a3abc7d Gtid list [] # at 285 #190907 17:15:09 server id 1 end_log_pos 331 CRC32 0x01d5789f Binlog checkpoint mysql-binlog.000001 # at 331 #190907 17:27:38 server id 1 end_log_pos 373 CRC32 0x17565195 GTID 0-1-1 ddl /*!100101 SET @@session.skip_parallel_replication=0*//*!*/; /*!100001 SET @@session.gtid_domain_id=0*//*!*/; /*!100001 SET @@session.server_id=1*//*!*/; /*!100001 SET @@session.gtid_seq_no=1*//*!*/; # at 373 #190907 17:27:38 server id 1 end_log_pos 483 CRC32 0xc4f951a5 Query thread_id=9 exec_time=0 error_code=0 use `ren`/*!*/; SET TIMESTAMP=1567848458/*!*/; SET @@session.pseudo_thread_id=9/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1/*!*/; SET @@session.sql_mode=1411383296/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8 *//*!*/; SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; DROP TABLE `test4` /* generated by server */ /*!*/; # at 483 #190907 17:28:11 server id 1 end_log_pos 525 CRC32 0x331814aa GTID 0-1-2 trans /*!100001 SET @@session.gtid_seq_no=2*//*!*/; BEGIN /*!*/; # at 525 #190907 17:28:11 server id 1 end_log_pos 630 CRC32 0x2a7828ea Query thread_id=9 exec_time=0 error_code=0 SET TIMESTAMP=1567848491/*!*/; delete from test where name='李連杰' /*!*/; # at 630 #190907 17:28:11 server id 1 end_log_pos 661 CRC32 0x13fd72a8 Xid = 22 COMMIT/*!*/; # at 661 #190907 17:30:06 server id 1 end_log_pos 703 CRC32 0x4fd1715e GTID 0-1-3 trans /*!100001 SET @@session.gtid_seq_no=3*//*!*/; BEGIN /*!*/; # at 703 #190907 17:30:06 server id 1 end_log_pos 809 CRC32 0xd387e70f Query thread_id=9 exec_time=0 error_code=0 SET TIMESTAMP=1567848606/*!*/; insert into test set name='漩渦鳴人' /*!*/; # at 809 #190907 17:30:06 server id 1 end_log_pos 840 CRC32 0x62252207 Xid = 23 COMMIT/*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
二進制日誌格式: #190613 14:17:32 server id 1 end_log_pos 666 CRC32 0xeb1cde6b Query thread_id=9 exec_time= 0 error_code=0 use `testdb`/*!*/; 事件發生的日期和時間:190613 14:17:32 事件發生的服務器標識:server id 1 事件的結束位置:end_log_pos 666 事件的類型:Query 事件發生時所在服務器執行此事件的線程ID:thread_id=9 語句的時間戳與將其寫入二進制文件中的時間差:exec_time=0 錯誤代碼:error_code=0 事件內容: GTID:Global Transaction ID; 專屬屬性:GTID
mysqlbinlog:客戶端命令工具 mysqlbinlog [options] log_file ... --start-datetime= --stop-datetime= --start-position= --stop-position=
複製架構中,備服務器用於保存主服務器的二進制日誌中讀取到的事件;用於實現mysql的主從複製。
一、查看中繼日誌變量
MariaDB [ren]> show global variables like "%relay%"; +-----------------------+----------------+ | Variable_name | Value | +-----------------------+----------------+ | max_relay_log_size | 1073741824 | | relay_log | | | relay_log_basename | | | relay_log_index | | | relay_log_info_file | relay-log.info | | relay_log_purge | ON | | relay_log_recovery | OFF | | relay_log_space_limit | 0 | | sync_relay_log | 10000 | | sync_relay_log_info | 10000 | +-----------------------+----------------+ 10 rows in set (0.00 sec)
二、變量詳解
1 relay_log fileName: 指定中繼日誌的文件名。【文件名爲空,表示禁用了中繼日誌】 2 relay_log_index: 索引表 3 relay_log_info_file: 記錄中繼日誌文件的相關信息 4 relay_log_purge: 指定是否自動刪除無用的中繼日誌文件 5 relay_log_recovery: 是否能夠對中繼日誌作自動恢復相關的配置 6 relay_log_space_limit: 指定中繼日誌能夠佔用的空間大小(0表示不限制)
三、SQL線程應用中繼日誌流程
事務日誌:transaction log(ib_logfile0,ib_logfile1)
一、查看參數
MariaDB [ren]> show global variables like '%innodb%log%'; +-------------------------------------------+------------+ | Variable_name | Value | +-------------------------------------------+------------+ | innodb_encrypt_log | OFF | | innodb_flush_log_at_timeout | 1 | | innodb_flush_log_at_trx_commit | 1 | | innodb_locks_unsafe_for_binlog | OFF | | innodb_log_arch_dir | | | innodb_log_arch_expire_sec | 0 | | innodb_log_archive | OFF | | innodb_log_block_size | 0 | | innodb_log_buffer_size | 16777216 | | innodb_log_checksum_algorithm | DEPRECATED | | innodb_log_checksums | ON | | innodb_log_compressed_pages | ON | | innodb_log_file_size | 50331648 | | innodb_log_files_in_group | 2 | | innodb_log_group_home_dir | ./ | | innodb_log_optimize_ddl | ON | | innodb_log_write_ahead_size | 8192 | | innodb_max_undo_log_size | 10485760 | | innodb_mirrored_log_groups | 0 | | innodb_online_alter_log_max_size | 134217728 | | innodb_scrub_log | OFF | | innodb_scrub_log_speed | 256 | | innodb_track_redo_log_now | OFF | | innodb_undo_log_truncate | OFF | | innodb_undo_logs | 128 | | innodb_use_global_flush_log_at_trx_commit | OFF | +-------------------------------------------+------------+ 26 rows in set (0.00 sec)
二、部分參數詳解
innodb_buffer_pool_size 通常設置成爲物理內存的3/4,或者4/5 innodb_log_files_in_group = 2 事務日誌文件的個數,默認爲2個事務日誌文件 innodb_log_file_size = 50331648(48m) 事務日誌文件的單個大小48m innodb_log_group_home_dir = ./ 事務日誌文件的所在路徑,默認就在mariadb的數據目錄/var/lib/mysql 事務型存儲引擎自行管理和使用(Innodb,myisam引擎是不支持事務,外鍵,行級鎖) redo log : 重作日誌 undo log :撤銷日誌 buffer_pool:緩衝池(通常而言,裝完數據庫第一個要調的參數)