MySQL Tutorial
MySQL Installation and Configuration
MySQL Database Operations
Database Design
MySQL Data Types
MySQL Storage Engines
MySQL Basic Operations of Tables
MySQL Constraints
MySQL Operators
MySQL Function
MySQL Manipulate Table Data
MySQL View
MySQL Indexes
MySQL Stored Procedure
MySQL Trigger
MySQL Transactions
MySQL Character Set
MySQL User Management
MySQL Database Backup and Recovery
MySQL Log
MySQL Performance Optimization
MySQL allows you to determine where the server sends output for the General Query Log and the Slow Query Log by setting the log_output
system variable. This setting can take one or multiple of the following values:
FILE
: Writes log output to files.TABLE
: Writes log output to tables in the mysql
database (general_log
and slow_log
).NONE
: Disables logging, which can be used to temporarily disable the logs without changing the other log_output
settings.The default value for log_output
is FILE
.
Setting the log output mode
You can set the log_output
mode in your MySQL configuration file (my.cnf or my.ini). Here's an example that sets log_output
to TABLE
:
[mysqld] log_output=TABLE
In this example, MySQL will write general and slow query logs to the general_log
and slow_log
tables in the mysql
database.
You can also set the log_output
mode to both FILE
and TABLE
:
[mysqld] log_output=TABLE,FILE
In this example, MySQL will write general and slow query logs to both files and tables. The log file names are determined by the general_log_file
and slow_query_log_file
system variables.
You can also change the log_output
value dynamically while the server is running using the SET
command. For example:
SET GLOBAL log_output = 'TABLE';
This command will set the global log_output
value to TABLE
. Note that this change is not persistent and will be reset when the server restarts.
Note: Modifying the MySQL configuration file and changing system variables typically require administrative privileges. Always be careful when modifying configuration files and ensure to back up any files before you modify them.
MySQL set log output mode:
[mysqld] log_output = FILE
Change log format in MySQL:
[mysqld] log_output = FILE log_json = ON
Configuring log output mode in MySQL:
[mysqld] log_output = CONSOLE
Switching log output modes in MySQL:
[mysqld] log_output = TABLE
Customize log output in MySQL:
[mysqld] general_log = 1 general_log_file = /path/to/general-query.log
Log verbosity levels in MySQL:
ERROR
, WARN
, INFO
, DEBUG
, and TRACE
.[mysqld] log_error_verbosity = 2
Setting log levels in MySQL:
[mysqld] log_error_verbosity = 1
Adjusting logging options in MySQL:
[mysqld] log-bin = /path/to/mysql-bin expire_logs_days = 7