ommysql: MariaDB/MySQL Database Output Module¶
Module Name: |
ommysql |
Author: |
Michael Meckelein (Initial Author) / Rainer Gerhards <rgerhards@adiscon.com> |
Purpose¶
This module provides native support for logging to MariaDB/MySQL databases. It offers superior performance over the more generic omlibdbi module.
Configuration Parameters¶
Note
Parameter names are case-insensitive; camelCase is recommended for readability.
Action Parameters¶
Parameter |
Summary |
|---|---|
Sets the MariaDB/MySQL server address the action connects to. |
|
Sets the Unix socket path to use when connecting to the MariaDB/MySQL server. |
|
Names the MariaDB/MySQL database that receives the log records. |
|
Defines the MariaDB/MySQL user account used for the connection. |
|
Specifies the password for the MariaDB/MySQL user defined in UID. |
|
Selects a non-standard port for the MariaDB/MySQL server connection. |
|
Selects an optional MariaDB/MySQL client configuration file (my.cnf) for the connection. |
|
Chooses the section within the client configuration file specified by MySQLConfig.File. |
|
Specifies the template used to format log records for insertion into the MariaDB/MySQL database. |
Failure and retry behavior¶
ommysql treats MariaDB/MySQL client and connection failures differently
from SQL data errors returned by the server.
Client-side connection failures, such as an unavailable server or a broken
connection, cause ommysql to reconnect and retry the failed statement once.
If reconnecting or retrying fails, the action is suspended. In that state, the
usual action retry settings, including action.resumeInterval and
action.resumeRetryCount, control when rsyslog tries to resume delivery.
Server-side SQL errors, such as a rejected INSERT or stored procedure call,
are treated as permanent data failures for the affected messages. rsyslog logs
the MySQL error and the failed SQL statement, then handles the failed message
through the action error-file path. These failures are not retried (and thus not
throttled by action.resumeInterval) because retrying the same malformed
statement later would normally fail in the same way. MySQL 8.0.24 and later has
one connection-related exception at the start of a transaction: error 4031
(ER_CLIENT_INTERACTION_TIMEOUT) reports that the server disconnected an
idle client due to wait_timeout or interactive_timeout. When this error
is returned by START TRANSACTION, ommysql reconnects and retries that
operation once, before any message SQL in that transaction has run. It does not
retry error 4031 for later SQL statements: reconnecting then could discard
earlier statements from the same transaction. MariaDB uses error 4031 for a
different SQL error, which remains a permanent data failure.
For production setups, configure action.errorfile on the ommysql action
when failed messages must be retained for inspection or replay. Without an error
file, permanently failed messages are discarded after rsyslog reports the action
failure.
Examples¶
Example 1¶
The following sample writes all syslog messages to the database “syslog_db” on mysqlserver.example.com. The server is being accessed under the account of “user” with password “pwd”.
module(load="ommysql")
action(type="ommysql" server="mysqlserver.example.com" serverPort="1234"
db="syslog_db" uid="user" pwd="pwd")
FAQ¶
Support: rsyslog Assistant | GitHub Discussions | GitHub Issues: rsyslog source project
Contributing: Source & docs: rsyslog source project
© 2008–2026 Rainer Gerhards and others. Licensed under the Apache License 2.0.