Log types in MySQL (2)-General query log
Brief introduction
General query log records connections and disconnections from the client, as well as every SQL statement sent from the client.
Log content format
The 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:
Record time
General Query Log records when the database receives a statement from the client. This means that the order of the General Query Log may be different from the order in which the actual statements are executed.
Setting method
General Query Log can be opened when the database is started or when the database is running.
Before the database starts:
Set-- general_log to open the log
Set-- log_output= [FILE,TABLE,NONE] to determine where the logs are 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, and 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 currently connected 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.
But regardless of the value of log_output, a startup message is written to the log file when the log is opened (or when the log file is refreshed). Examples of startup information are as follows: