MySQL logs and index

MySQL physical structure:

    It is a MySQL data stored and managed by the file system, into the log files and data files from the physical structure

Log files:

 

Log file records the information and misinformation database operations, we used the log files are: error logs, binary logs, query logs, slow query log, InnoDB engine online redo logs and relay logs and so on.

Error log (err log):

Is enabled by default state, if it is version 5.5.7 is not closed after the error log , error log that records all serious error messages encountered during the operation, as well as detailed information on each MySQL startup and shutdown.

The default error log name: hostname.err

 

Error logs record that we can log-ERRO r and log-warnings to define, where the log-err is to define whether the storage location of the error log function and error logging is enabled, log-warnings is to define whether a warning message is also defined to the error log. log_error file path can be directly defined, or may be the ON | OFF ; log_warings only use 1 | 0 to define the start switch

Binary log (bin log):

The default is off, we need to: log-bin = mysql-bin were open, which mysql-bin is a bin-log log file basename, the default name of bin-log log file: mysql-bin-000001.log

binlog It records all DDL statements and DML statements in the database, but does not includeselect statements contents, statements stored in the form of events, describes the change order data,binlog also includes the execution time information for each update statement,binl-og main role is torecover the data, so thebin-log for disaster recovery and backup and recovery is essential for.

If DDL statements are recorded directly to bin-log log, and DML statements required to submit records to the bin-log log through a transaction

bin-log can also be used for MySQL master copy from

Copy the master-slave principle:

 

 

 

 

 The General Query Log (general query log):

Is off by default, due to the general query log records all operation of the user, which also contains information such as additions and deletions to change search, in large concurrent operating environment will generate a lot of information leading to unnecessary disk IO, it will affect the performance of mysql of. Should not the database for debugging purposes is not recommended to open query log.

Slow query log (slow query log):

It is off by default, by setting the: slow_query_log the ON = be opened. Record execution time exceeds long_query_time all queries seconds, facilitate the collection of long time query SQL statement

MySQL Index:

我们使用索引的目的就是在于:优化查询速度,索引是一种特殊的文件或者叫数据结构(InnoDB数据表上的索引是表空间的一个组成部分),它们包含着对数据表里所有记录的引用指针。更通俗的说,数据库索引好比是一本书前面的目录,能加快数据库的查询速度。

索引是在储存引擎中实现的,不同的储存引擎就会使用不同的索引,默认是使用BTREE索引,

索引的分类:

单列索引 (常用)

 

        普通索引:MySQL中基本索引类型,没有什么限制,允许在定义索引的列中插入重复值和空值,纯粹为了查询数据更快一点。

 

        唯一索引:索引列中的值必须是唯一的,但是允许为空值

 

         主键索引:是一种特殊的唯一索引不允许有空值

组合索引(常用):

     在表中的多个字段组合上创建的索引,只有在查询条件中使用了这些字段的左边字段时,索引才会被使用,使用组合索引时遵循最左前缀集合

全文索引:

 

      全文索引,只有在MyISAM引擎上才能使用,只能在CHAR,VARCHAR,TEXT类型字段上使用全文索引。

 

 

索引的使用:

创建索引:

 

1.CREATE index 索引名 ON 表名(列名(长度))

删除索引:

DROP index 索引名 ON 表名

查看执行计划:

  只需在sql语句前加 EXPLAIN 

索引的储存结构:


 

 

 

 

     

 

 

Guess you like

Origin www.cnblogs.com/grow001/p/12112861.html