Log Files in the MySQL database

Source: Internet
Author: User
2.3 configure the query log output path starting from 5.1.6. MySQL provides a more flexible way to control the output and output paths of log files. MySQL standard logs (specifically general_log and slow_log) can be output to files and stored in the same name table of mysql database in the form of tables. Before MySQL 5.1.6, only logs are logged.

2.3 configure the query log output path starting from 5.1.6. MySQL provides a more flexible way to control the output and output paths of log files. MySQL standard logs (specifically general_log and slow_log) can be output to files and stored in the same name table of mysql database in the form of tables. Before MySQL 5.1.6, only logs are logged.

2.3 configure the log output path for query

MySQL provides a more flexible way to control the output and output paths of log files from version 5.1.6. MySQL standard logs (specifically general_log and slow_log) can be output to files and stored in the same name table of mysql database in the form of tables. Before MySQL 5.1.6, only logs are recorded to files.

    Tip:

    From version 5.1.6, the log table is created along with other system tables during installation. If the log is upgraded from version 5.1.6 or earlier, you must manually upgrade the system table to ensure that the log table exists.

Currently, logging to a dedicated log table of the system consumes more system resources than Recording files. Therefore, to enable logging, you must obtain higher system performance, we recommend that you record files first.

However, recording to the system table also has its advantages. For example, this type of table can be easily authorized to allow all users connected to the MySQL database to view the recorded content in the log, in addition, log tables can be accessed through SQL statements, which can also easily filter data through the powerful functions of SQL statements, which are not easy to implement in log files.

2.3.1 configure when the service is started

MySQL command lines can load many parameters at startup, and a log-output parameter is provided to specify the log file output mode. Note, it refers to the output mode, that is, whether to record files in the operating system or to a dedicated table in the database system.

The -- log-output parameter has three optional values:

  • TABLE: A log TABLE recorded in the database;
  • FILE: records the log FILE. The default value is FILE (in versions 5.1.6 to 5.1.20, the default value is TABLE );
  • NONE: no record.

You can specify multiple parameter values at the same time and separate them with commas.

When the -- log-output parameter value is not set to NONE, it is possible to continue setting the log file output path. To control the generation of common query logs or slow query log files, there are other parameters:

  • -- General_log: determines whether to generate common query logs. Two optional values: 1 (Enabled) and 0 (Disabled). The default value is 0, however, if this parameter is specified but the parameter value is not specified, the default value is 1;
  • -- General_log_file: this parameter is supported after version 5.1.29. It is used to specify the file name and output path of a common query log file. The default file name is [host_name]. log;
  • -- Slow_query_log: determines whether to generate slow query logs. Two optional values: 1 (Enabled) and 0 (Disabled). The default value is 0, however, if this parameter is specified but the parameter value is not specified, the default value is 1;
  • -- Slow_query_log_file: this parameter is supported after version 5.1.29. It is used to specify the file name and output path of the slow query log file. The default file name is [host_name]-slow. log:

    Tip:

    Before Version 5.1.29, there were no -- general_log_file and -- slow_query_log_file parameters. The two parameters -- log and -- log-slow-queries were used to control the file name and output path.

  • -- Log: Specifies the output path of a common query log and enables the log output function. The default file name is [host_name]. log. this parameter is discarded after version 5.1.29;
  • -- Log-slow_queries: Specifies the output path of the slow query log and enables the log output function. The default file name is [host_name]-slow. log, which is discarded after 5.1.29.

If the description of literature is unclear, let's take a look at the following examples to strengthen it, for example:

  • If only common query logs are enabled and recorded in log files and log tables, the following parameters are set when mysql is started:

    -- Log-output = TABLE, FILE -- general_log

  • Enable common query logs and slow query logs to log tables in the database. when mysql is started, set the following parameters:

    -- Log-output = TABLE -- general_log -- slow_query_log

  • Only enable slow query logs and record them to log files. Set the parameters as follows:

    -- Log-output = FILE -- slow_query_log

  • Only enable slow query logs, record the logs to the log file, and specify the output path. Set the parameters as follows:

    -- Log-output = FILE -- slow_query_log -- slow_query_log_file =/data/mysql/logs/slow. log

2.3.2 configuration in Service Running

MySQL provides many system environment variables to control the running status of MySQL services.

Many system variables have extremely high similarity with MySQL command line parameters, and even include the same name, function, and Parameter Value Syntax. If there is a difference, that is, the command line parameter is called during command execution. Once set, it cannot be modified unless you re-run the command line. Many system environment variables, dynamic Modification is supported during the service running process, which includes some parameters related to the log file Configuration:

  • Log_output:
  • General_log & slow_query_log:
  • General_log_file & slow_query_log_file:

The above parameters support global dynamic modification. The functions of the parameters are identical to those of the same name in the preceding command line, so we will not talk about them much. The following parameter is particularly described:

  • SQL _log_off: the optional parameter value is ON/OFF (1/0 or. The setting of MySQL system environment variables is very flexible. It will be described in another chapter ), the statement used to specify whether to enable or disable the execution of the current session to record normal query logs. The default value is OFF. This parameter is a session-level parameter. You must have the SUPER permission to set this option.

========================================================== ====
Serialization:

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.