Logging SQL errors plugin.

You are viewing an old version of this article. View the current version here.

Sometimes it's useful to collect errors set to clients in a log file, that can later be analyzed. The SQL_ERROR_LOG plugin added to the MariaDB 5.5 allows to do that. It implemented as the MYSQL_AUDIT_PLUGIN, so after installed the plugin receives error notification from the server and stores them to the specified file. The log file can be rotated.

The typical command to enable the SQL errlog plugin:

	install plugin SQL_ERROR_LOG soname 'sql_errlog.so';

or by adding --plugin-load=sql_errlog.so to the server's command line or to the [mysqld] section in your my.cnf file.

and to disable it:

	uninstall plugin SQL_ERROR_LOG;

The SQL_ERROR_LOG plugin declares 5 variables that control it's behaviour:

  • @sql_error_log_filename - string value. The name of the logfile.
    rotation of it will be named like @sql_error_log_filename.001
  • @sql_error_log_rate - integer value, the rate of logging.
    SET @sql_error_log_rate:=300; means that one of 300 errors will be written to the log.
    If the @sql_error_log_rate is 0 - the logging is disabled.
    The default rate is 1 (each error is logged).
  • @sql_error_log_size_limit - integer value, the limitation for the size of the log file.
    After reaching the specified limit, the log file is rotated.
    1M limit set by default.
  • @sql_error_log_rotations - integer value, 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.
  • @sql_error_log_rotate - boolean value.
    This is the 'write-only' variable. Assigning TRUE to this variable forces the log rotation.

Comments

Comments loading...
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.