5.2 MySQL server log---------------------mysql log types: 1. Error log: Problems encountered when starting, running, stopping mysqld 2, common query log: establishing client connections and receiving from clients Received statements 3, binary log: Change the data log (also used for [master-slave] replication) 4, Relay log: Master-slave replication, the main server will own binary log sent to the server, called the relay log 5, slow query log: Execution time over Long_que
Ry_time query 6, DDL log (metadata log): Metadata options executed by DDL statements by default, all logs are not enabled except for error logs on Windows; By default, the server writes logs to the MySQL data directory; We can get the server to shut down and reopen the log file by refreshing the log, and execute the mysqladmin command with flush-logs or refresh parameters using the Flush logs statement. Executing the mysqldump command with--flush-logs or--master-data options causes the log to refresh, and the binary log is refreshed when it reaches the size of the max_binlog_size system variable, and the normal query log and the slow query log can run , you can turn the log on or off, you can change the log file name, you can tell the server to write the normal query log and the binary log to the log or log file, or both both; the relay log is only used for master-slave copying; ++++++++++++++++++++ 5.2 .1 Select the normal query log and the slow query log output destinations ++++++++++++++++++++ for the normal query log and slow query log outputs, MySQL provides flexible control; can be output to a log file or The General_log and Slow_log tables (files and tables 2 output destinations can be selected at the same time); control log at startup:--log-output option specifies the log output destination; syntax is--log-output=[valu
E,...] 1, if given this option when given a value, this value should be one or more comma-delimited list: fortables, table; for files: file; This value can also be none, so that the log is neither written nor written to the file, and if none is specified, it has the highest precedence; 2, if--log The-output option is omitted, the default log output location is the file; the system variable General_log controls the output of the normal query log, and if specified at startup, General_log uses optional parameter 1 or 0 to control whether or not to open Open the normal query log; If you want to use a custom log file, set General_log_file this system variable; (similar to normal query log, the variable of the control log output used by the slow query log is slow_query_log and Slow_ Query_log_file; If the log is turned on, the server will write the startup information, but unless the location of the log file is selected, a further query log will not be written to the file (specify whether to open the log or not; Records are not recorded; for example: 1. If you want to write the common query log to both the file and the table, use--log-output=table,file to select the two output destinations at the same time, and use the--quer Y_log to open the ordinary query log; 2, if you just want to write the ordinary query log or slow query log to the table, use--log-output=table to the log output destination, but also to use--general_log or--slow_quer
Y_log to open the 2 kinds of logs, 3, if you just want to write a slow query log to the file, use--log-output=file file as the log output destination, but also use--slow_query_log to open a slow query log; In this case, because the default log output destination is a file,--log-output can be omitted; run-time control log: Global variable log_output indicates the output destination of the current log, which can be modified at run time
Variable to control the log output position; Global variables General_log and slow_query_log indicate whether the normal query log and the slow query log are open (on), and you can modify the 2 variables at run time to control whether to open the log in these 2; global variables general_log_file and S Low_query_log_file shows the common query log and the slow query log file, you can set these 2 variables to change the log file when the server is open or running; If you want to turn on or off the normal query log for the current connection, you can set the session variable Sql_log_off to ON or off; there are several benefits to using a table for logging: 1. The log entity has a standard format; You can use the following statement to view the structure of the current log table: Show CREATE
A TABLE Mysql.general_log;
Show Createa TABLE Mysql.slow_log; 2, through the SQL statement can access the log content; This allows us to query the log that satisfies a particular rule, 3, can access the log at any client that has access to the current server, without logging on to the current server through the file system; Log table implementation has Features: 1. Typically, the purpose of the log table is to provide an interface to the user to monitor runtime exceptions to the server; 2, CREATE table, ALTER table, DROP table for log table Said to be a lawful operation; for ALTER TABLE and drop table operations, the log table cannot be used; 3. By default, the log table uses the CSV storage engine, which writes the data in a comma-delimited format, for those that can access the log data. CSV file, this file can easily be imported into other programs; The log tables can be altered to use the MyISAM storage engine. You are cannot use ALTER TABLE to alter a log TABLE of that. TheLog must be disabled.
No engines other than CSV or MyISAM are legal for the log tables.
If we want the ALTER TABLE or DROP table, we first turn off the log, as an example of the normal query log: SET @old_log_state = @ @global. general_log;
SET GLOBAL general_log = ' off ';
ALTER TABLE Mysql.general_log ENGINE = MyISAM;
SET GLOBAL general_log = @old_log_state;
The TRUNCATE table operation is legal for the log table, and the RENAME table operation is also valid for the log table: use MySQL;
DROP TABLE IF EXISTS general_log2;
CREATE TABLE general_log2 like General_log;
RENAME TABLE General_log to General_log_backup, general_log2 to General_log; CHECK TABLE Legal LOCK tables Illegal INSERT DELETE UPDATE cannot be used on the log table; FLUSH tables W ITH READ LOCK and variable read_only have no effect on the log table, which is written in the log table, is not written to the binary log, and therefore cannot be copied to the server; you want to refresh the log table or log file, use flush tables
and FLUSH LOGS;
The log table cannot be partitioned; Mysqldump saves the statement for rebuilding the log table so that it can be recovered from the dump file, but the data for the log table is not saved; ++++++++++++++++++++ ++++++++++++++++++++ +++++++
+++++++++++++
++++++++++++++++++++
++++++++++++++++++++