SQL Error Log Plugin

MariaDB starting with 5.5.22

The SQL_ERROR_LOG plugin was first released in MariaDB 5.5.22.

The SQL_ERROR_LOG plugin collects errors sent to clients in a log file defined by sql_error_log_filename, so that they can later be analyzed. The log file can be rotated if sql_error_log_rotate is set.

Comments are also logged, which can make the log easier to search. But this is only possible if the client does not strip the comments away. For example, mysql command-line client only leaves comments when started with the --comments option.

It is implemented as a MYSQL_AUDIT_PLUGIN.

Installing the Plugin

Although the plugin's shared library is distributed with MariaDB by default, the plugin is not actually installed by MariaDB by default. There are two methods that can be used to install the plugin with MariaDB.

The first method can be used to install the plugin without restarting the server. You can install the plugin dynamically by executing INSTALL SONAME or INSTALL PLUGIN. For example:

INSTALL SONAME 'sql_errlog';

The second method can be used to tell the server to load the plugin when it starts up. The plugin can be installed this way by providing the --plugin-load or the --plugin-load-add options. This can be specified as a command-line argument to mysqld or it can be specified in a relevant server option group in an option file. For example:

[mariadb]
...
plugin_load_add = sql_errlog

Uninstalling the Plugin

You can uninstall the plugin dynamically by executing UNINSTALL SONAME or UNINSTALL PLUGIN. For example:

UNINSTALL SONAME 'sql_errlog';

If you installed the plugin by providing the --plugin-load or the --plugin-load-add options in a relevant server option group in an option file, then those options should be removed to prevent the plugin from being loaded the next time the server is restarted.

Example

install plugin SQL_ERROR_LOG soname 'sql_errlog';
Query OK, 0 rows affected (0.00 sec)

use test;
Database changed

set sql_mode='STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected (0.00 sec)

CREATE TABLE foo2 (id int) ENGINE=WHOOPSIE;
ERROR 1286 (42000): Unknown storage engine 'WHOOPSIE'
\! cat data/sql_errors.log
2013-03-19  9:38:40 msandbox[msandbox] @ localhost [] ERROR 1286: Unknown storage engine 'WHOOPSIE' : CREATE TABLE foo2 (id int) ENGINE=WHOOPSIE

Versions

VersionStatusIntroduced
1.0StableMariaDB 10.1.13
1.0GammaMariaDB 10.0.10
1.0AlphaMariaDB 5.5.22

System Variables

sql_error_log_filename

  • Description: The name of the logfile. Rotation of it will be named like sql_error_log_filename.001
  • Commandline: --sql-error-log-filename=value
  • Scope: Global
  • Dynamic: No
  • Data Type: string
  • Default Value: sql_errors.log
  • Introduced:

sql_error_log_rate

  • Description: The rate of logging. SET sql_error_log_rate=300; means that one of 300 errors will be written to the log.
    If sql_error_log_rate is 0 the logging is disabled.
    The default rate is 1 (every error is logged).
  • Commandline: --sql-error-log-rate=#
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 1
  • Introduced:

sql_error_log_rotate

  • Description: This is the 'write-only' variable. Assigning TRUE to this variable forces the log rotation.
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: OFF
  • Introduced:

sql_error_log_rotations

  • Description: The number of rotations. When rotated, the current log file is stored and the new empty one created.
    The sql_error_log_rotations logs are stored, older are removed.
    The default number of rotations is 9.
  • Commandline: --sql-error-log-rotations
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 9
  • Range: 1 to 999
  • Introduced:

sql_error_log_size_limit

  • Description: The limitation for the size of the log file. After reaching the specified limit, the log file is rotated.
    1M limit set by default.
  • Commandline: --sql-error-log-size-limit=#
  • Scope: Global
  • Dynamic: No
  • Data Type: numeric
  • Default Value: 1000000
  • Range: 100 to 9223372036854775807
  • Introduced:

Comments

Comments loading...