SQL Error Log Plugin

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.

Errors are logged as they happen and an error will be logged even if it was handled by a condition handler and was never technically sent to the client.

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.

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

Version Status Introduced
1.0 Stable MariaDB 10.1.13
1.0 Gamma MariaDB 10.0.10
1.0 Alpha MariaDB 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

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

sql_error_log_rotate

  • Description: This is the 'write-only' variable. Assigning TRUE to this variable forces the log rotation.
  • Commandline: --sql-error-log-rotate={0|1}
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: OFF

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: No
  • Data Type: numeric
  • Default Value: 9
  • Range: 1 to 999

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

Options

sql_error_log

  • Description: Controls how the server should treat the plugin when the server starts up.
    • Valid values are:
      • OFF - Disables the plugin without removing it from the mysql.plugins table.
      • ON - Enables the plugin. If the plugin cannot be initialized, then the server will still continue starting up, but the plugin will be disabled.
      • FORCE - Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error.
      • FORCE_PLUS_PERMANENT - Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error. In addition, the plugin cannot be uninstalled with UNINSTALL SONAME or UNINSTALL PLUGIN while the server is running.
    • See Plugin Overview: Configuring Plugin Activation at Server Startup for more information.
  • Commandline: --sql-error-log=value
  • Data Type: enumerated
  • Default Value: ON
  • Valid Values: OFF, ON, FORCE, FORCE_PLUS_PERMANENT

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.

© 2021 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/sql-error-log-plugin/