InnoDB storage engine - file

1. Parameter File

When the MySQL instance starts, the database will go to read a configuration parameter file (by default my.cnf), used to find the locations of the various files in the database resides and to specify certain initialization parameters that define some kind of memory how much structure and so on.

Although MySQL instance starts if can not find the my.cnf, will use the default configuration information to start, but if you can not find the mysql architecture (that is, a database library file, which records information on the various parameters of MySQL instance ) as fail to start.

(1) What are the parameters

Can be seen as key-value pair, many property databases are optimized according to the parameters.

You can view all parameters in the database via the command SHOW VARIABLES

(2) Parameter Type

In MySQL parameters can be divided into two categories:

  1. Dynamic parameters: You can change the MySQL instance
  2. Static parameters: the life cycle of the entire instance can not be modified

2. Log Files

  • Error Log
  • Slow query log
  • Query Log
  • Binary Log

(1) The error log

MySQL error log to start the run, shut down the recording process. File Error file name server host name (such as benjamin.err) by default.

(2) Slow query log

Slow query log can screen out potentially problematic SQL statements SQL statements to run according to the time, to help developers locate, so as to optimize the SQL statement level.

By default, this feature is not activated, long_query_time this parameter is 0, if you set a value greater than 0, will record all run SQL statements beyond this time MySQL database runtime (not recorded exactly equal to the value of statements). from the start of MySQL 5.1 microseconds, before seconds.

Another is that, if a SQL statement does not use the index, then the same will be recorded to the slow query log.

From MySQL 5.6.5 version adds parameters log_throttle_queries_not_using_indexes, used to represent every minute inserted into the slow query the maximum number of logs, the default is 0.

MySQL 5.1 from the start can speak slow query log records to a table in the mysql architecture, called slow_log. Log_output parameter specifies the slow query log output format, the default is FILE, can be set to TABLE, you can check mysql architecture slow_log under the table. this parameter is global and dynamic, may be modified online.

InnoSQL enhanced version does not live the way SQL statements, the new statistics for logical read (all read) and physical reads (the number of IO read from disk) in slow_log in the original basis.

The number of times than the specified logical record IO SQL statements into parameters by show_log long_query_io, the default value is 100

Enable ways to enable show_log to represent the optional parameter values ​​have show_query_type

  • 0 means no SQL statements to show log record
  • 1 shows a running time of SQL statements to show log record
  • 2 shows a logical record number of IO SQL statement to show log
    3 shows a number of run-time and logic IO SQL statement to show log record

(3) The query log

Query logging all the information requested on the MySQL database, regardless of whether these requests were performed correctly, will be recorded. The default file name is the host name .log.

(4). Binary Log

Binary logging of all operations performed changes to the MySQL database, but does not include select and show this kind of operations, since such operation does not modify the data. Operation Instant other operating data is not valid data modification, also recorded the binary log.

The binary log also includes other additional information and time to perform database operations change, in general, have a look at several functions:

  • Recovery: for data recovery after the downtime occurs.
  • Copy: modification of data by recording the complete data can be obtained, and thereby are replicated database.
  • Audit: Are there any injection attacks by the binary information audit log.

If you do not specify a name, the default is the host name of the serial number (eg: bin_log.000001)..

Binary log files by default does not open the case, you need to manually specify the parameters to start.

bin_log.index binary index file for binary number storage past log generated

The following parameters affect the configuration file binary logging information and behavior

  • max_binlog_size
  • binlog_cache_size
  • sync_binlog
  • binlog-do-db
  • binlog-ignore-db
  • log-slave-update
  • binlog_format

Max_binlog_size parameter specifies the maximum size of a single binary file. The default value is 1 073 741 824 (1G).

All binary log uncommitted transactions will be recorded to a buffer to wait for the transaction is submitted in written from the buffer of the binary log file. When the contents of the log buffer larger than this top binlog_cache_size, will generate temporary binary log files are stored in the buffer.

By default, the binary log is not synchronized each time to write to disk, so that when downtime occurs, there may be no written part, recovery and replication will cause problems. Parameters sync_binlog = [N] It indicates how many times did not write buffer is synchronized to disk.

Parameters binlog-do-db and binlog-ignore-db expressed the need to write or ignore what is written in the log library

Parameters binlog_format very important parameters affecting the recording format of the binary log, is usually set to ROW values ​​can be set:

  • STATEMENT: Logical SQL statement logging.
  • ROW: Change the recording table.
  • MIXED: Use the form STATEMENT record of default, there are some cases will use the form to record ROW:
    • NDB storage engine for the table
    • Use the UUID (), USER (), CURRENT_USER (), FOUND_ROWS (), ROW_COUNT () function and other uncertainties
    • Use the INSERT DELAY statement
    • Use a user-defined function
    • Use a temporary table

To view the binary log file, you must tools provided by MySQL mysqlbinlog.

3. socket file

UNIX System MySQL local connection if UNIX domain socket way, the need for a socket file, the file can be controlled socket parameters, typically in / tmp directory, called mysql.sock

4. pid file

Record their process id, located in the default database directory, file name is the host name .pid.

5. The table structure definition file

Because the relationship between architecture MySQL pluggable storage engine, MySQL database is stored, but no matter what kind of storage engine table using the memory according to the table, each table has the corresponding file, there will be a MySQL as to frm suffix files, records the table structure definition table.

frm is also used to store the definition of the view, the file is a text file that can be used directly view the cat.

6. InnoDB Storage Engine Files

(1) Table space files

InnoDB using design data stored by the table storage space, the initial default configuration will have a size of 10MB, the file name ibdata1 This file is the default file tablespace.

Can be set by the file path innodb_data_file_path parameters, of course, also be provided a plurality of load paths to the average disk:

innodb_data_file_path=/dir/filename1:/dir/filename2

After setting the parameters innodb_data_file_path, based on all the records of the table are InnoDB storage engine to the shared data table space. Innodb_file_per_table If the parameter settings for each user can generate a table based on a separate table space InnoDB storage engine. Naming rules .ibd for the table name. These individual data file stores only tablespace the table, insert buffer BITMAP index and other information, or the rest of the information stored in the default table space

(2) redo log files

Files in the data directory the InnoDB storage engine have two named ib_logfile0 and ib_logfile1 of. The official referred to in the MySQL manual for the InnoDB storage engine log file, a precise definition should redo log file records for InnoDB storage engine transaction logs.

When an instance fails or is turned off, InnoDB storage engine is the use of redo logs to restore the database to the state before the failure occurs, in order to ensure data integrity.

Each InnoDB storage engine with at least one group redo log file, at least two redo log files under each file group.

Consistent log group size of each redo log files, and run in a circular fashion.

Several important parameters redo log files

  • innodb_log_file_size: Specifies the size of each redo log file
  • innodb_log_files_in_group: specifies the number of log file group redo log files, the default is 2
  • innodb_mirrored_log_groups: specifies the number of log file mirroring group, the default is 1
  • innodb_log_group_home_dir: specifies the path to the log file group where the default is ./

Difference redo log files binary log file:

  • Different range of records, the binary log file records all MySQL database-related logs, including all engines, while the redo log file records only transactions InnoDB storage engine itself.
  • Different contents of the record, the binary log file records the operating conditions of a transaction, and redo log file records each page was modified on the physical level.
  • Write different time, the binary log file only commit before the transaction commits, write disk only once, and redo log files during the conduct of affairs will continue to insert entries to the redo log file.

In the InnoDB storage engine, there are different for different operating redo log format, but they have a basic format

redo_log_type space page_no redo_log_body
1 byte indicating the type of redo logs A table space ID, a compressed manner, thus occupying the space may be less than 4 bytes Offset indicates the page, using the same compression method Portion of each redo log data indicating the need to call the appropriate function parses recovery
Published 141 original articles · won praise 47 · views 40000 +

Guess you like

Origin blog.csdn.net/qq_41596568/article/details/104332364