MySQL log operations

Source: Internet
Author: User
Tags mysql slow query log

    • MySQL log mysql log type :
      error log :-log-err
      Log the startup, run, and stop MySQL service problems of the MySQL service
      query log :-log
      Record established client connections and executed statements
      Slow query log :-log-slow-queries
      Log all queries that have been executed for more than long_query_time, or queries that do not use indexes
      Update log :-log-update
      Binary log :-log-bin
      A statement that records all change data and can be used for data replication
      1. First verify that your log is enabled
         
           
          
      1. mysql>show variables like ‘log_%‘;

      If enabled, on

2. How to know the current log

 
   
  
  1. mysql> show master status;

3. Look at the binary log file with Mysqlbinlog

 
   
  
  1. shell>mysqlbinlog mail-bin.000001
How do I open a binary query?

By default, the binary log is turned off, and you can start and set up the binary log by modifying the MySQL configuration file:
There are several settings in the MY.CNF [mysqld] group that are related to the binary log:

  
 
  1. log-bin[=PATH/[FILENAME]]
  2. expire_logs_days=10
  3. max_binlog_size=100M
  4. server-id = 1//这一行必须要,因为数据库有主从之分

log-binDefine open binary log; path indicates the directory where the log file resides;
filename Specifies the name of the log file, such as the full name of the file is filename.0001,filename.0002, etc.
In addition to the above file, there is a file that becomes Filename.index, the file content is a list of all logs, you can use Notepad to open the file
expire_logs_daysDefines the time that MySQL clears an expired log, that is, the number of days that the binary log is automatically deleted. The default value is 0, which means "no automatic deletion". The file may be deleted when MySQL starts or refreshes the binary log
max_binlog_sizeDefines the size limit for a single file, which scrolls if the contents of the binary log are written beyond the given value
(Close the current file and reopen a new log file.) You cannot set this variable to be greater than 1GB or less than 4096 bytes. The default value is 1GB

How do I turn on slow queries?

If the log_slow_queries status is off, no slow query is currently turned on.
It is very simple to turn on slow queries, as follows:
In [mysqld], add the following information:

  
 
  1. [mysqld]
  2. log-slow-queries[=PATH/[FILENAME]]
  3. long_query_time = 4
  4. log-queries-not-using-indexes

log-slow-queries: On behalf of the MySQL slow query log storage directory, this directory file must have write permission;
long_query_time: Maximum execution time. (, MSYQL will record all the execution time more than 2 SQL statements, here is the test time, the time should not be too small preferably within 5-10 seconds, of course, according to their own standards);
log-queries-not-using-indexes: Queries that do not use an index are also recorded in the log
Configure the MySQL service to restart later
service mysqld restart



From for notes (Wiz)

MySQL log operations

Related Article

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.