Home > Database > Mysql Tutorial > Example analysis of log operations in MySQL

Example analysis of log operations in MySQL

黄舟
Release: 2017-08-01 11:07:50
Original
969 people have browsed it

In the early days of MySQL, you need to be proficient in the use of sql statements. The simplest way is to practice more and use them more, but it needs to have a certain purpose. What does it mean?

That is, everyone has different habits and may make different mistakes. Therefore, you need to summarize your common mistakes and make targeted corrections. This will help you learn and master MySQL with twice the result with half the effort. Effect. Today I will talk about several types of logs that record MySQL operations:

#Error log log-error

#Query log log

#Binary log log-bin

#Slow log log-slow-queries

#Update log log-update (official recommendation, do not enable it, so ignore it here)

Details below:

1. First, after logging in to mysql, execute the sql statement:

show variables like 'log_bin';
Copy after login

Check whether the log is enabled. The detailed results are as shown in the figure:

Example analysis of log operations in MySQL

Example analysis of log operations in MySQL

2.#Error log log-error

How to open:

Under the [mysqld] option of my.ini:

Add code:

log-error=E:\log-error.txt
Copy after login

Record content:

Mainly records fatal problems that occur when starting, running or stopping mysqld. They are system-level error records as shown in the figure:

Example analysis of log operations in MySQL

3.#Query log log

How to open:

Under the [mysqld] option of my.ini:

Add code:

log=E:/mysql_log.txt
Copy after login

Record content:

Mainly records the client connection established by the database and the executed statements as shown in the figure:

Example analysis of log operations in MySQL

Example analysis of log operations in MySQL

4.#Binary log log-bin

How to open:

Under the [mysqld] option of my.ini:

Add code:

log-bin=E:/mysql_log_bin
Copy after login

Record content:

Mainly records all statements that change data. You can use the mysqlbinlog command to restore the data. As shown in the picture:

Example analysis of log operations in MySQL

5.# Slow log log-slow-queries

Opening method:

In [mysqld of my.ini ] option:

Add code:

long_query_time =1 (设定慢查询的标准,单位是s/秒)
    log-slow-queries= E:/mysql_log_slow.txt
Copy after login

Record content:

Mainly records all queries whose execution time exceeds long_query_time or queries that do not use indexes, as shown in the figure :

Example analysis of log operations in MySQL

Notes

The txt document is opened with an editor, and the format is a bit messy when opened with Notepad

The above is the detailed content of Example analysis of log operations in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template