MySQL- database file

1 Overview

  The main database files contain MySQL database level and file-level storage engine 2 types of files.

1) Database-level document has a parameter file (my.cnf / my.ini), the error file (error log), slow query file (slow log), general query file (genral log), binaries (bin log), in following the log file (relay log), audit logs (auidt log), socket file (socket), documents the process id (pid file) and file table structure (.frm)

2) storage engine level, there redo log files and undo log log file

 

2. The document provides information on the database level

2.1 Parameter File

  Save the default user profile or a user-defined operation options. For mysqld service starts.

1) See Example boot priority order parameter file read process

mysql --help|grep -A1 'Default options'
mysqld --verbose --help |more

2) command parameters (parameter type: according to whether you can modify parameters online divided into two categories, dynamic parameters and static parameters)

mysql> set [global|session] parameter=value;

3) Check the parameters

mysql> show variables;
mysql> show vairalbes like '%parameter%';

 

2.2 error log file

  MySQL error logging startup, operation, shut down problems arising in the course. Generally stored in the data directory

show variables like 'log_error';
select @@log_error;

SELECT VARIABLE_NAME, VARIABLE_VALUE FROM performance_schema.global_variables WHERE VARIABLE_NAME in ( 'log_error', 'log_warnings');

 

2.3 binary log (binary log)

  For recording all operations real changes (DML statements), and statements recorded time of occurrence, duration execution, data manipulation, and so on. Does not include those statements do not modify any data not recorded show, select statements.

  1) binary log format commonly used definition:

    1, the statement (statement): The default recording format;

    2, line (row): What is the definition of data is not the data itself but the line is;

    3, mixed mode (mixed): alternating line and expression, by mysql server discretion.

    Based on the amount of data which define the format of the line will be larger but can guarantee the accuracy of the data.

  2) On / Off binary log

- writing papers (permanent) 
VI / etc / the my.cnf
 [ mysqld ] 
log - bin [ = the DIR \ [filename ] ] 

- command mode (provisional) 
SET Global log - bin =  . 1 ;

  3) Delete the binary log:

  Binary log will record a lot of information (which contains some useless information). If the binary log does not clean up a long time, it will waste a lot of disk space. However, after the deletion may lead to the collapse of the database can not be recovered, so first of all to remove the binary log and its backup copy of the database, which can only be deleted before the backup binary logs, the new log information generated can not be deleted (you can do instant point reduction). It can not be directly deleted because it might give the wrong database brought in after closing mysql server. If not to delete the binary logs need to do the following: Export backup database and log files are compressed binary archive storage.

- 1. RESET MASTER statement delete all binary logs 

MySQL > RESET Master; 
MySQL > Show binary logs; 

- 2. The binary log files to delete or point in time 

MySQL > the PURGE { BINARY  | the MASTER the LOGS} { the TO  ' log_name '  | bEFORE datetime_expr} 

- where TO'log_name' represents the other documents before the files are deleted, can also use binary files before bEFORE datetime_expr delete the specified time. 

MySQL > the PURGE BINARY the LOGS the TO  ' MySQL-bin.000007 ' ; 
MySQL > the PURGE BINARYThe BEFORE LOGS ' 2020-03-10 10:26:36 ' ; # use the time to delete the binary logs

 

2.4 slow query log (slow log)

  All time record of more than long_query_time statements recorded. Slow query log file can be viewed by mysqldumpslow tool or percona-toolkit tools to help DBA to optimize slow queries.

-- 相关参数
SELECT
      VARIABLE_NAME
     ,VARIABLE_VALUE
-- ,GROUP_CONCAT("'",VARIABLE_NAME,"'")
FROM
    performance_schema.global_variables 
WHERE
    VARIABLE_NAME in ( 'slow_query_log', 'slow_query_log_file','long_query_time','');

Slow query log analysis tool

- Output top 10 queries according to time dimension 
the mysqldumpslow - ST - T 10  < slow_query_log_file >

 

 

3. innodb storage engine logs

  innodb storage engine level, there are two main log (redo log and undo log). Multiple versions innodb is achieved by using undo and rollback. InnoDB is an index table organization, to achieve three rows each hidden column (DB_ROW_ID, DB_TRX_ID, DB_ROLL_PTR) represent the number of rows in each row, and rollback transaction ID pointers.

3.1 redo log log file

   recording redo log transaction for operating the change, the value of the recorded data is modified.

  redo log records all operations on all innodb database. It is used to make crash recover the database is to ensure data security features heavy. InnoDD storage engine, there are two default log file (ib_logfile0, ib_logfile1)

3.2 undo log log file | rollback (undo log seg)

  Not only will generate redo records when the records do change operation, also have undo records.

  undo log records only the old data before change, recording undo records to the system default table space (ibdata1), may be provided after separate undo tablespace mysql5.6.

 

 

 

Guess you like

Origin www.cnblogs.com/wandering-mind/p/12463011.html