Mysql-related log aggregation _ MySQL

Source: Internet
Author: User
As an important means of querying problems, log should be recorded as much as possible for you to query some problems. MySQL has the following types of logs:-log-err query log:-log slow query log:-log-slow-queries update log: -log-updat logs are an important means of querying problems. Therefore, you should record the logs you need as much as possible for yourself to query some problems.

MySQL has the following types of logs:

Error log:-log-err
Query log:-log
Slow query log:-log-slow-queries
Update log:-log-update
Binary log:-log-bin
By default, all logs are created in the mysqld data directory. By refreshing logs, you can force mysqld to close and reopen the log file (or switch to a new log in some cases ). When you execute a flush logs statement or mysqladmin flush-logs or mysqladmin refresh, the log is refreshed.

1. error log

Use the -- log-error [= file_name] option to specify the location where mysqld saves the error log file. If the file_name value is not specified, mysqld uses the error log name host_name.err and writes the log file to the data directory. If you execute flush logs, the error log uses-old to rename the suffix and mysqld to create a new empty log file. (If the -- log-error option is not provided, it will not be renamed ).
If -- log-error is not specified, or (in Windows) if you use the -- console option, the error is written to stderr. Standard output is usually your terminal.

2. general query logs
Use the -- log [= file_name] or-l [file_name] option to start it. If the file_name value is not specified, the default name is host_name.log.

3. slow query logs
When the -- log-slow-queries [= file_name] option is enabled, mysqld writes a log file containing all SQL statements whose execution time exceeds long_query_time. if the file_name value is not given, no host name is provided by default, and the suffix is-slow. log. If the file name is provided but not the absolute path name, the file is written to the data directory.

3. Update logs
Start with the -- log-update [= file_name] option. it is not recommended.


Whether logs are enabled
Mysql> show variables like 'log _ % ';
How to know the current log
Mysql> show master status;
Display the number of binary logs
Mysql> show master logs;
Use mysqlbinlog to view binary log files
Shell> mysqlbinlog mail-bin.000001
Or shell> mysqlbinlog mail-bin.000001 | tail

Specify the log output location in the configuration file.
Windows: the configuration file for Windows is my. ini, which is usually in the MySQL installation directory or c: \ Windows.
Linux: the configuration file of Linux is my. cnf, which is usually in/etc.
In linux:
SQL code
In [mysqld], enter
Log
Log-error =/usr/local/mysql/log/error. log
Log =/usr/local/mysql/log/mysql. log
Long_query_time = 2 -- indicates how long the SQL statement will be logged after execution. here, it is 2 seconds.
Log-slow-queries =/usr/local/mysql/log/slowquery. log
Enter # log in [mysqld]
Log-error =/usr/local/mysql/log/error. log
Log =/usr/local/mysql/log/mysql. log
Long_query_time = 2
Log-slow-queries =/usr/local/mysql/log/slowquery. log

Windows:
SQL code
In [mysqld], enter
Log
Log-error = "E:/PROGRA ~ 1/EASYPH ~ 1.0B1/mysql/logs/error. log"
Log = "E:/PROGRA ~ 1/EASYPH ~ 1.0B1/mysql/logs/mysql. log"
Long_query_time = 2
Log-slow-queries = "E:/PROGRA ~ 1/EASYPH ~ 1.0B1/mysql/logs/slowquery. log"
Enter # log in [mysqld]
Log-error = "E:/PROGRA ~ 1/EASYPH ~ 1.0B1/mysql/logs/error. log"
Log = "E:/PROGRA ~ 1/EASYPH ~ 1.0B1/mysql/logs/mysql. log"
Long_query_time = 2

Log-slow-queries = "E:/PROGRA ~ 1/EASYPH ~ 1.0B1/mysql/logs/slowquery. log"

You can add the desired logs for your own analysis and use.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.