The error log contains information indicating when mysqld was started and stopped and also any critical errors that occur while the server is running. If mysqld notices a table that needs to be automatically checked or repaired, it writes a message to the error log.
In the following discussion, “console” means
stderr, the standard error output; this is your
terminal or console window unless the standard error output has
been redirected. (For example, if invoked with the
mysqld_safe arranges for the server's
stderr to be sent to
as described later.)
If no log file name is specified, the default log file is
in the data directory, unless the
--pid-fileoption is specified. In that case, the default name is the PID file base name with a suffix of
.errin the data directory.
--log-error[=, mysqld writes error messages to an error log file. mysqld writes to the named file if present, creating it in the data directory unless an absolute path name is given to specify a different directory. If no file is named, mysqld writes to the default log file.
In addition, on Windows, the server writes events and error
messages to the Windows Event Log within the Application log.
Entries marked as
Note are written to the Event Log, but not
informational messages such as information statements from
individual storage engines. These log entries have a source of
MySQL. You cannot disable writing information
to the Windows Event Log.
On Unix and Unix-like systems, mysqld writes error log messages as follows:
--log-error[=, mysqld writes error messages to an error log file. The server uses the named file if present, creating it in the data directory unless an absolute path name is given to specify a different directory. If no file is named, the default name is
in the data directory.
variable indicates the error log file name if error output is
written to a file.
If you flush the logs using
FLUSH LOGS or
mysqladmin flush-logs and
mysqld is writing the error log to a file (for
example, if it was started with the
--log-error option), the effect is
As of MySQL 5.1.51, the server closes and reopens the log file. To rename the file, do so manually before flushing. Then flushing the logs reopens a new file with the original file name. For example, to rename the file and create a new one, use the following commands:
On Windows, use rename rather than mv.
Prior to MySQL 5.1.51, the server renames the current log file with the suffix
-old, then creates a new empty log file. Be aware that a second log-flushing operation thus causes the original error log file to be lost unless you save it under a different name. On Windows, you cannot rename the error log while the server has it open before MySQL 5.1.51. To avoid a restart, flush the logs first to cause the server to rename the original file and create a new one, then save the renamed file. That also works on Unix, or you can use the commands shown earlier.
If the server is not writing to a named file, no error log renaming occurs when the logs are flushed.
Before 5.1.20, mysqld_safe behavior is to log to a file, using the default error log file if the
--log-erroroption is not given to mysqld_safe. Otherwise, mysqld_safe uses the file name specified using
In 5.1.21 and up, the default with no logging options is
--skip-syslog, which is compatible with the default behavior of writing an error log file for releases prior to 5.1.20. To explicitly specify use of an error log file, specify
--log-error=to mysqld_safe, and mysqld_safe will arrange for mysqld to write messages to a log file. To use
sysloginstead, specify the
In 5.1.20 only, the following conditions apply: 1) The default is to use
syslog, which is not compatible with releases prior to 5.1.20. 2) Logging to
syslogmay fail to operate correctly in some cases; if so, use
For logging to
syslog, messages from mysqld_safe and mysqld are written with a tag of
mysqld, respectively. As of MySQL 5.1.21, to specify a suffix for the tag, use
--syslog-tag=, which modifies the tags to be
--log-warnings option or
log_warnings system variable can
be used to control warning logging to the error log. The default
value is enabled (1). Warning logging can be disabled using a
value of 0. If the value is greater than 1, aborted connections
are written to the error log. See
Section B.5.2.11, “Communication Errors and Aborted Connections”.