Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 38.0Mb
PDF (A4) - 38.0Mb
PDF (RPM) - 37.3Mb
HTML Download (TGZ) - 10.2Mb
HTML Download (Zip) - 10.2Mb
HTML Download (RPM) - 8.9Mb
Man Pages (TGZ) - 216.6Kb
Man Pages (Zip) - 329.3Kb
Info (Gzip) - 3.5Mb
Info (Zip) - 3.5Mb
Excerpts from this Manual

5.4.2 The Error Log

This section discusses how to configure the MySQL server for logging of diagnostic messages to the error log. For information about selecting the error message character set or language, see Section 10.1.6, “Error Message Character Set”, or Section 10.2, “Setting the Error Message Language”.

The error log contains a record of mysqld startup and shutdown times. It also contains diagnostic messages such as errors, warnings, and notes that occur during server startup and shutdown, and while the server is running. For example, if mysqld notices that a table needs to be automatically checked or repaired, it writes a message to the error log.

On some operating systems, the error log contains a stack trace if mysqld exits abnormally. The trace can be used to determine where mysqld exited. See Section 28.5, “Debugging and Porting MySQL”.

If used to start mysqld, mysqld_safe may write messages to the error log. For example, when mysqld_safe notices abnormal mysqld exits, it restarts mysqld and writes a mysqld restarted message to the error log.

The following sections discuss aspects of configuring error logging. In this discussion, console means stderr, the standard error output. This is your terminal or console window unless the standard error output has been redirected to a different destination.

The server interprets options that determine where to write error messages somewhat differently for Windows and Unix systems. Be sure to configure error logging using the information appropriate to your platform.

Error Logging on Windows

On Windows, mysqld uses the --log-error, --pid-file, and --console options to determine whether mysqld writes the error log to the console or a file, and, if to a file, the file name:

  • If --console is given, mysqld writes the error log to the console. (--console takes precedence over --log-error if both are given, and the following items regarding --log-error do not apply. Prior to MySQL 5.7, this is reversed: --log-error takes precedence over --console.)

  • If --log-error is not given, or is given without naming a file, mysqld writes the error log to a file named host_name.err in the data directory, unless the --pid-file option is specified. In that case, the file name is the PID file base name with a suffix of .err in the data directory.

  • If --log-error is given to name a file, mysqld writes the error log to that file (with an .err suffix added if the name has no suffix), located under the data directory unless an absolute path name is given to specify a different location.

If the server writes the error log to the console, it sets the log_error system variable to stderr. Otherwise, the server writes the error log to a file and sets log_error to the file name.

In addition, the server by default writes events and error messages to the Windows Event Log within the Application log:

  • Entries marked as Error, Warning, and Note are written to the Event Log, but not messages such as information statements from individual storage engines.

  • Event Log entries have a source of MySQL.

  • Information written to the Event Log is controlled using the log_syslog system variable, which on Windows is enabled by default. See Error Logging to the System Log.

Error Logging on Unix and Unix-Like Systems

On Unix and Unix-like systems, mysqld uses the --log-error option to determine whether mysqld writes the error log to the console or a file, and, if to a file, the file name:

  • If --log-error is not given, mysqld writes the error log to the console.

  • If --log-error is given without naming a file, mysqld writes the error log to a file named host_name.err in the data directory.

  • If --log-error is given to name a file, mysqld writes the error log to that file (with an .err suffix added if the name has no suffix), located under the data directory unless an absolute path name is given to specify a different location.

  • If --log-error is given in an option file in a [mysqld], [server], or [mysqld_safe] section, mysqld_safe finds and uses the option, and passes it to mysqld.

Note

It is common for Yum or APT package installations to configure an error log file location under /var/log with an option like log-error=/var/log/mysqld.log in a server configuration file. Removing the file name from the option causes the host_name.err file in the data directory to be used.

If the server writes the error log to the console, it sets the log_error system variable to stderr. Otherwise, the server writes the error log to a file and sets log_error to the file name.

Error Logging to the System Log

It is possible to have mysqld write the error log to the system log. This is the Event Log on Windows, and syslog on Unix and Unix-like systems. To do so, use these system variables:

  • log_syslog: Enable this variable to send the error log to the system log. (On Windows, log_syslog is enabled by default.)

    If log_syslog is enabled, the following system variables can also be used for finer control.

  • log_syslog_facility: The default facility for syslog messages is daemon. Set this variable to specify a different facility.

  • log_syslog_include_pid: Whether to include the server process ID in each line of syslog output.

  • log_syslog_tag: This variable defines a tag to add to the server identifier (mysqld) in syslog messages. If defined, the tag is appended to the identifier with a leading hyphen.

Note

Logging to the system log may require additional system configuration. Consult the system log documentation for your platform.

On Unix and Unix-like systems, control of output to syslog is also available using mysqld_safe, which can capture server error output and pass it to syslog.

Note

Using mysqld_safe for syslog error logging is deprecated; you should use the server system variables instead.

mysqld_safe has three error-logging options, --syslog, --skip-syslog, and --log-error. The default with no logging options or with --skip-syslog is to use the default log file. To explicitly specify use of an error log file, specify --log-error=file_name to mysqld_safe, which then arranges for mysqld to write messages to a log file. To use syslog, specify the --syslog option. For syslog output, a tag can be specified with --syslog-tag=tag_val; this is appended to the mysqld server identifier with a leading hyphen.

Error Log Verbosity

The log_error_verbosity system variable controls server verbosity for writing error, warning, and note messages to the error log. Permitted values are 1 (errors only), 2 (errors and warnings), 3 (errors, warnings, and notes), with a default of 3. If the value is greater than 2, the server logs aborted connections and access-denied errors for new connection attempts. See Section B.5.2.10, “Communication Errors and Aborted Connections”.

Error Log Message Format

The ID included in error log messages is that of the thread within mysqld responsible for writing the message. This indicates which part of the server produced the message, and is consistent with general query log and slow query log messages, which include the connection thread ID.

The log_timestamps system variable controls the time zone of timestamps in messages written to the error log (as well as to general query log and slow query log files). Permitted values are UTC (the default) and SYSTEM (local system time zone).

Error Log File Flushing and Renaming

If you flush the logs using FLUSH ERROR LOGS, FLUSH LOGS, or mysqladmin flush-logs, the server closes and reopens any error log file to which it is writing. To rename an error log file, do so manually before flushing. Flushing the logs then opens a new file with the original file name. For example, assuming a log file name of host_name.err, to rename the file and create a new one, use the following commands:

mv host_name.err host_name.err-old
mysqladmin flush-logs
mv host_name.err-old backup-directory

On Windows, use rename rather than mv.

If the location of the error file is not writable by the server, the log-flushing operation fails to create a new log file. For example, on Linux, the server might write the error log as /var/log/mysqld.log, where /var/log is owned by root and not writable by mysqld. For information about handling this case, see Section 5.4.7, “Server Log Maintenance”.

If the server is not writing to a named error log file, no error log file renaming occurs when the logs are flushed.


User Comments
Sign Up Login You must be logged in to post a comment.