Server Log Maintenance
549
To include slow administrative statements in the statements written to the slow query log, use the
--
log-slow-admin-statements
[412]
server option. Administrative statements include
ALTER
TABLE
,
ANALYZE TABLE
,
CHECK TABLE
,
CREATE INDEX
,
DROP INDEX
,
OPTIMIZE TABLE
, and
REPAIR TABLE
.
To include queries that do not use indexes for row lookups in the statements written to the slow query
log, use the
--log-queries-not-using-indexes
[412]
server option. See
Section 5.1.3, “Server
Command Options”
. When such queries are logged, the slow query log may grow quickly.
The server uses the controlling parameters in the following order to determine whether to write a query
to the slow query log:
1. The query must either not be an administrative statement, or
--log-slow-admin-
statements
[412]
must have been specified.
2. The query must have taken at least
long_query_time
[465]
seconds, or
--log-queries-
not-using-indexes
[412]
must have been specified and the query used no indexes for row
lookups.
The server does not write queries handled by the query cache to the slow query log, nor queries that
would not benefit from the presence of an index because the table has zero rows or one row.
Replication slaves do not write replicated queries to the slow query log, even if the same queries were
written to the slow query log on the master. This is a known issue. (Bug #23300)
The slow query log should be protected because logged statements might contain passwords. See
Section 6.1.2.3, “Passwords and Logging”
.
The slow query log can be used to find queries that take a long time to execute and are therefore
candidates for optimization. However, examining a long slow query log can become a difficult task.
To make this easier, you can process a slow query log file using the
mysqldumpslow
command to
summarize the queries that appear in the log. See
Section 4.6.8, “
mysqldumpslow
— Summarize
Slow Query Log Files”
.
5.2.5. Server Log Maintenance
As described in
Section 5.2, “MySQL Server Logs”
, MySQL Server can create several different log files
to help you see what activity is taking place. However, you must clean up these files regularly to ensure
that the logs do not take up too much disk space.
When using MySQL with logging enabled, you may want to back up and remove old log files from time
to time and tell MySQL to start logging to new files. See
Section 7.2, “Database Backup Methods”
.
On a Linux (Red Hat) installation, you can use the
mysql-log-rotate
script for this. If you installed
MySQL from an RPM distribution, this script should have been installed automatically. Be careful with
this script if you are using the binary log for replication. You should not remove binary logs until you are
certain that their contents have been processed by all slaves.
On other systems, you must install a short script yourself that you start from
cron
(or its equivalent) for
handling log files.
For the binary log, you can set the
expire_logs_days
[450]
system variable to expire binary log
files automatically after a given number of days (see
Section 5.1.4, “Server System Variables”
). If you
are using replication, you should set the variable no lower than the maximum number of days your
slaves might lag behind the master. To remove binary logs on demand, use the
PURGE BINARY LOGS
statement (see
Section 13.4.1.1, “
PURGE BINARY LOGS
Syntax”
).
You can force MySQL to start using new log files by flushing the logs. Log flushing occurs when you
issue a
FLUSH LOGS
statement or execute a
mysqladmin flush-logs
,
mysqladmin refresh
,
mysqldump --flush-logs
, or
mysqldump --master-data
command. See
Section 13.7.6.2,
“
FLUSH
Syntax”
,
Section 4.5.2, “
mysqladmin
— Client for Administering a MySQL Server”
, and
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...