mysql log inventory system

MySql log file mainly contains: the error log, slow query log, transaction logs, binary logs, etc.

Mysql can log configuration command 

1 show global variables like '%log%'; 

Implementation of the results is as follows

"back_log"    "80"
"binlog_cache_size"    "32768"
"binlog_checksum"    "CRC32"
"binlog_direct_non_transactional_updates"    "OFF"
"binlog_error_action"    "ABORT_SERVER"
"binlog_format"    "ROW"
"binlog_group_commit_sync_delay"    "0"
"binlog_group_commit_sync_no_delay_count"    "0"
"binlog_gtid_simple_recovery"    "ON"
"binlog_max_flush_queue_time"    "0"
"binlog_order_commits"    "ON"
"binlog_row_image"    "FULL"
"binlog_rows_query_log_events"    "OFF"
"binlog_stmt_cache_size"    "32768"
"expire_logs_days"    "0"
"general_log"    "OFF"
"general_log_file"    "DESKTOP-VH518HU.log"
"innodb_api_enable_binlog"    "OFF"
"innodb_flush_log_at_timeout"    "1"
"innodb_flush_log_at_trx_commit"    "1"
"innodb_locks_unsafe_for_binlog"    "OFF"
"innodb_log_buffer_size"    "1048576"
"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_write_ahead_size"    "8192"
"innodb_max_undo_log_size"    "1073741824"
"innodb_online_alter_log_max_size"    "134217728"
"innodb_undo_log_truncate"    "OFF"
"innodb_undo_logs"    "128"
"log_bin"    "OFF"
"log_bin_basename"    
"log_bin_index"    
"log_bin_trust_function_creators"    "OFF"
"log_bin_use_v1_row_events"    "OFF"
"log_builtin_as_identified_by_password"    "OFF"
"log_error"    ".\DESKTOP-VH518HU.err"
"log_error_verbosity"    "3"
"log_output"    "FILE"
"log_queries_not_using_indexes"    "OFF"
"log_slave_updates"    "OFF"
"log_slow_admin_statements"    "OFF"
"log_slow_slave_statements"    "OFF"
"log_statements_unsafe_for_binlog"    "ON"
"log_syslog"    "ON"
"log_syslog_tag"    
"log_throttle_queries_not_using_indexes"    "0"
"log_timestamps"    "UTC"
"log_warnings"    "2"
"max_binlog_cache_size"    "18446744073709547520"
"max_binlog_size"    "1073741824"
"max_binlog_stmt_cache_size"    "18446744073709547520"
"max_relay_log_size"    "0"
"relay_log"    
"relay_log_basename"    "C:\ProgramData\MySQL\MySQL Server 5.7\Data\DESKTOP-VH518HU-relay-bin"
"relay_log_index"    "C:\ProgramData\MySQL\MySQL Server 5.7\Data\DESKTOP-VH518HU-relay-bin.index"
"relay_log_info_file"    "relay-log.info"
"relay_log_info_repository"    "FILE"
"relay_log_purge"    "ON"
"relay_log_recovery"    "OFF"
"relay_log_space_limit"    "0"
"slow_query_log"    "ON"
"slow_query_log_file"    "DESKTOP-VH518HU-slow.log"
"sql_log_off"    "OFF"
"sync_binlog"    "1"
"sync_relay_log"    "10000"
"sync_relay_log_info"    "10000"

First, the error log

As the query configuration file, log_error is the storage location of the error log file configuration, mysql error log is forced open. The main recording detailed information of each mysql server startup and shutdown, as well as all the more serious warning and error messages during operation, etc., content format as follows:

 1 2019-07-28T09:05:15.396749Z 9 [Note] Aborted connection 9 to db: 'unconnected' user: 'root' host: 'localhost' (Got an error reading communication packets)
 2 2019-07-28T10:34:57.643413Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
 3 2019-07-28T10:34:57.646421Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
 4 2019-07-28T10:34:57.660459Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe (mysqld 5.7.17-log) starting as process 2548 ...
 5 2019-07-28T10:34:57.762731Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
 6 2019-07-28T10:34:57.764737Z 0 [Note] InnoDB: Uses event mutexes
 7 2019-07-28T10:34:57.774763Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
 8 2019-07-28T10:34:57.781781Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
 9 2019-07-28T10:34:57.784789Z 0 [Note] InnoDB: Adjusting innodb_buffer_pool_instances from 8 to 1 since innodb_buffer_pool_size is less than 1024 MiB
10 2019-07-28T10:34:57.810859Z 0 [Note] InnoDB: Number of pools: 1
11 2019-07-28T10:34:57.823893Z 0 [Note] InnoDB: Not using CPU crc32 instructions
12 2019-07-28T10:34:57.834922Z 0 [Note] InnoDB: Initializing buffer pool, total size = 8M, instances = 1, chunk size = 8M
13 2019-07-28T10:34:57.840938Z 0 [Note] InnoDB: Completed initialization of buffer pool
14 2019-07-28T10:34:57.902190Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
15 2019-07-28T10:34:57.910212Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 172728817
16 2019-07-28T10:34:57.910212Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 172728826
17 2019-07-28T10:34:57.912216Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 172728826
18 2019-07-28T10:34:57.912216Z 0 [Note] InnoDB: Database was not shutdown normally!
19 2019-07-28T10:34:57.913219Z 0 [Note] InnoDB: Starting crash recovery.
20 2019-07-28T10:34:58.941953Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
21 2019-07-28T10:34:58.941953Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
22 2019-07-28T10:34:58.942956Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
23 2019-07-28T10:34:59.177579Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB.
24 2019-07-28T10:34:59.181591Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
25 2019-07-28T10:34:59.182593Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
26 2019-07-28T10:34:59.182593Z 0 [Note] InnoDB: Waiting for purge to start
27 2019-07-28T10:34:59.239188Z 0 [Note] InnoDB: 5.7.17 started; log sequence number 172728826
28 2019-07-28T10:34:59.245204Z 0 [Note] InnoDB: Loading buffer pool(s) from C:\ProgramData\MySQL\MySQL Server 5.7\Data\ib_buffer_pool
29 2019-07-28T10:34:59.253225Z 0 [Note] Plugin 'FEDERATED' is disabled.
30 2019-07-28T10:34:59.331405Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190728 18:34:59
31 2019-07-28T10:34:59.331405Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
32 2019-07-28T10:34:59.332409Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
33 2019-07-28T10:34:59.378531Z 0 [Note] IPv6 is available.
34 2019-07-28T10:34:59.378531Z 0 [Note]   - '::' resolves to '::';
35 2019-07-28T10:34:59.379534Z 0 [Note] Server socket created on IP: '::'.
36 2019-07-28T10:34:59.643220Z 0 [Note] Event Scheduler: Loaded 0 events
37 2019-07-28T10:34:59.644222Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check. 
38 2019-07-28T10:34:59.645225Z 0 [Note] Beginning of list of non-natively partitioned tables
39 2019-07-28T10:34:59.920058Z 0 [Note] End of list of non-natively partitioned tables
40 2019-07-28T10:34:59.921060Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: ready for connections.
41 Version: '5.7.17-log'  socket: ''  port: 3306  MySQL Community Server (GPL)

Second, slow query log

 Slow query log mainly records mysql time execution of a long sql, the default threshold is 10 seconds, the execution time of over 10 seconds sql statement will be slow query log that records the slow query configuration log can configuration files in the mysql configure

SLOW - Query - log = 1   // 0 means closed; 1 to turn 
slow_query_log_file = "DESKTOP - VH518HU - SLOW. log " // slow query the storage location of the log files 
long_query_time = 10  // in seconds, represents the slow query time, The default more than 10 seconds counted once slow query

 

 Sql statement query is slow to begin until the end of the statement from, including acquiring the lock, retrieve data, and return a series of process data. If a simple sql statement needs to acquire a lock in the process of implementation, and the lock has been occupied by another firm, will likely be slow query records

 

Third, the transaction log

InnoDB transaction logs include redo log and undo log two types

It refers to a redo log redo log, before providing rolling operation, typically the physical log, modified data record is the physical page, instead of a row or a few rows modified case, to restore the data of the physical page after submission

undo log is rolled back log value, providing rollback operation, to roll back to a recorded version, typically logical logs, according to each of rows rollback

3.1, redo log (redo log)

 redo log comprising three parts:

redo log buffer: innodb buffer, mysql innodb is running in user space of the operating system, when the transaction commits, will first redo log is written in memory, which is memory, user space

os buffer: buffer kernel space, redo log required final brush plate into a log file, you need to log saved to disk by the kernel space, so you need to redo log buffer is written to the user space kernel space os buffer

redo log file: redo log file on disk, and then place orders equivalent to redo log persistence to complete

Therefore persistence step redo log on as shown below:

 redo log buffer is written first user space to kernel space os buffer, and then writes the data in kernel space in the redo log file of the disk file by a method fsync

redo log brush plate There are three ways you can provide configuration innodb_flush_log_at_trx_commit  be configured to indicate how the transaction commits after the log buffer is flushed to disk, the default value of 1,

When the value is 0: When the transaction commits, the redo log buffer is not written os buffer, but to redo log buffer is written per os buffer, and call fsync () will os buffer is written redo log file

When the value is 1: When a transaction is committed, it will redo log buffer is written os buffer, and call fsync () will log File os buffer is written redo (the default configuration, the system can fail without loss of data, but less IO performance )

When the value of 2: when a transaction is committed, will redo log buffer is written os buffer, but does not execute immediately fsync (), but performs a fsync () per second os buffer is written redo log file

By default, the configuration will use a value of 1, because in order to ensure that data is not lost, and the performance is almost the other two cases, much better than the situation 1, but in extreme cases lose one second of data, in in the case of high concurrency, the amount of data for one second is great.

 

redo log format

Innodb storage unit is page data, the redo log is recorded based on the format of the page, by default, innodb page size is 16K, and the number of the redo log redo block, each redo block is 512 bytes, a can hold a lot of log block,

Recorded in the log block is the change in the data page, in the following format:

redo_log_type: 1 byte indicating the type of the redo log log

space: indicates the ID of table space, after a compressed manner, may be less than the space occupied by 4 bytes

page_no: a rear offset page, the same compression

redo_log_body: redo part of the log

 

3.2, undo log (rollback log)

rollback undo log may be provided a plurality of rows and Versioning (MVCC)

When the transaction commits, not only need to keep the redo log, will undo log records, or rolled back if the transaction fails, you need to be rolled back by undo log

logical undo log record is a log, such as when a delete statement transaction commit, then the undo log is recorded corresponding to the insert statement, the transaction is equivalent to the reverse operation sql.

When performing rollback, it can be read from the logical undo log record to the appropriate content and rollback. Sometimes when applied to the row versioning, and it is achieved through the undo log: When a line is read locked by another transaction, it can analyze what the bank records previous data from the undo log, providing the line version of the information, allowing users to achieve a non-locking consistent reads.

In addition undo log will generate redo log

 

Fourth, the binary log (bin log)

 bin log log records are used to update the database (insert, update, delete), and primarily to restore the database from the synchronization master mysql, mysql primary synchronization is transmitted from the master node through the bin log for the node from node to update the data by bin log file reaches the data consistency effect

 bin log of configuration can command show variables like '% log_bin%' query, the default is off

The main bin log format parameter binlog_format controlled, there are three statement, row, mixed

When the value statement: sql statement specific storage bin log in to perform, such as insert, update, delete, etc., but may be data inconsistencies arise, such as sql statement using the NOW (), SLEEP () and other real-time when the function is executed each time the results will be different

When the value of row: bin log stored in the latest updated data for all rows, this would resolve data inconsistencies, but the log file will be relatively large, such as the first option for each sql only generate a log, while the use of row may be a way to update operation affects multiple records, logs will produce multiple of,

And if the entire table is updated, it will be the entire table data will be logged, it is clear this approach has a lot of deficiencies

When the value is mixed: bin log according to the specific sql statement using the first or second embodiment, the equivalent of two ways combines the advantages of

 

bin log recording time

bin log log will be written after the transaction commits, or may be asynchronous, sync_binlog parameters can be configured, when sync_binlog = n, the execution of n represents sql statement written once, if the setting value is 1, it indicates that every sql transaction will be submitted to sync written to disk

Is actually written os buffer, and redo log, are used to determine when the configuration of the brush plate by innodb_flush_log_at_trx_commit

 

innodb by recording redo log, undo log bin log and ensure durability, consistency and atomicity of the data, and when the recovery start database recovery operation may be performed in accordance with redo log database

 

Guess you like

Origin www.cnblogs.com/jackion5/p/11259395.html