Brief introduction
General query log records the connection and disconnection of the client and every SQL statement sent from the client.
Log Content Format
General query log can be recorded in a file or in a table in the following format:
The time, thread ID, command type, and statements executed are recorded in the file
Examples are as follows:
When the log is recorded in the table, the account information is also recorded, as shown in the following example:
Recording time
General Query Log is logged when the database receives a statement from the client. This means that the order of the general Query log may differ from the order in which the actual statements are executed.
Setup method
General Query Log can be turned on when the database is started, or it can be opened when the database is running.
Before the database starts:
Set--general_log to turn on logging
Set--log_output=[file,table,none] To determine where the log is stored.
Set--general_log_file=file_name to determine the name and directory of the log file.
While the database is running:
Modify global variables to modify log settings
Modify the values of General_log, Log_output, general_log_file to modify the relevant settings, for example:
SET GLOBAL general_log=1
SET GLOBAL log_output= ' FILE ';
In addition, you can disable or enable the current connection's general query log by setting the value of Sql_log_off to on or off.
Other
The database writes the log to a file or table based on the value of Log_output.
However, regardless of the value of Log_output, when the log is turned on (or when the log file is refreshed), a startup message is written to the log file. The boot information example is as follows:
Log type in MySQL (ii)-general query log