Integrating MariaDB Audit plugin in MySQL 5.7


Basically, Auditing is the process of monitoring and recording the activity happens inside the Server. MariaDB Audit Plugin is works with MariaDB, MySQL and Percona Servers. It is used to log the database Operations like, SQL Statements, User informations, Connections. The informations are stored in a user defined log file or in Syslog.

Available audit plugins for MySQL.

MariaDB Audit plugin more easy to implement and it has better filtering option. Most of the options are online and do not need a server restart. ( old versions has serious bugs). This plugin is compatible with Oracle MySQL, Percona Server and MariaDB. We have implemented it with MySQL 5.7 latest.


In LINUX MariaDB audit plugin installation contains below simple steps.

Step I)

Download the tar archive file for Audit plugin from the MariaDB. (MariaDB Audit Plugin Download )


Step II)

Extract the downloaded tar archive file.


Step III)

Copy the plugin to plugin directory in MySQL based on your linux server (64 bit/32 bit).

cp server_audit-1.4.0/linux-x86-64/ /usr/lib64/mysql/plugin/

chown -R mysql.mysql  /usr/lib64/mysql/plugin/

Step IV)

Install the MariaDB Audit Plugin into the MySQL Server.


INSTALL PLUGIN ‘plugin name’ SONAME ‘’;

For example,


Note: While installation the (.so) file must be placed inside the plugin Directory, Otherwise the Installation will be failed.

Logging formats:

We have two formats for logging like, file and syslog. By using the Option “server_audit_output_type” we can change the formats. For example,

Syslog format,


File format,




MariaDB Audit-Plugin logging the Output like this above screenshot. It have the Details like timestamp, server host, username, host, connectionid, queryid, operation, database, object, retcode. They are recorded in CSV format .Either JSON or XML is not supported.

MariaDB Audit-Plugin variables:

Below are the variables list for MariaDB Audit Plugin.


We can also get the variables using “show global variables” Query. From this Blog we have see the detail explanation about variables “server_audit_events”, “server_audit_incl_users” and “server_audit_excl_users


This is the variable used to allow the logging. By default the logging is in OFF condition we need to enable this. After enable the variable “server_audit_logging” the plugin starts the logging.



The variable “Server_audit_events” is used to define logging from the Server. We have 6 type of logs in MariaDB-Audit-Plugin.

  1. Connect
  2. Query
  3. Query_DML
  4. Query_DDL
  5. Query_DCL

(i) Connect:

If we enable “Connect” in ‘server_audit_events‘ it logs all connects, disconnects and the failed connects with error code. We can enable it on both config file and Global.


After enable server_audit_events=connect, the output be like this,

Screenshot from 2016-04-16 15-08-31.pngddddd

From this Output,

DISCONNECT denotes the server exit.

CONNECT denotes the server login

FAILED denotes the connection error and 1045 is error code.


It logs all the details about the Query executing in the server like, executed Query and issued Query with error code. We can enable it in config file and global.


The output logs like,


From this output we can see both fine query and issued query.

DB name         : MySQL

Table name     : user

Select * from mysql.user   — Query is fine

Select * from mysql.users — issued query with error code = 1146

(iii) Query_DML:

The variable “Query_DML” logs only the DML operations like SELECT, INSERT, UPDATE, DELETE, MERGE. We can enable it in both config file and global.


The output logs like,


From this output we can able to see the SELECT, UPDATE and INSERT Operations.

(iv) Query_DDL:

The variable “Query_DDL” logs only the DDL operations like CREATE, ALTER, DROP, TRUNCATE. It benefitsWe can enable it in both config file and global.


The output logs like,


The Output log files contains the DDL Statements.

(v) Query_DCL:

It logs only the DCL operations like GRANTS and REVOKE. We can enable it in both config file and Global. It benefits more in security for the list of users added and grants provided.


The output logs like,


The logs contains only the Queries like GRANTS and REVOKE, and the error query had the error code too. It is better to use a log rotate with the output log file.

Note: If we need more options like, Query_ddl, Query_DML, Query_DCL just make the options with comma. For example,



If we need to audit a specific user operations this option will be helps for that kind of job. We can enable it in both config and global. It logs all the operations for that particular user based on the “server_audit_events” variables.


We can also add few users using comma.



It is the variable performs the single or list of users mentioned in the variable, whose activities are not logged. We can enable it in both config file and global.


It is empty, not working becoz previously, we activate the user “mysql and root” as a incl_users. So it is empty.

We  need to remove that user’s (mysql,root) from incl_users. After that we can perform the same.


Now, the users (mysql, root) were added to the excl_users.


MariaDB Audit-Plugin is used to log the server operations based on our needs. MariaDB has better filtering than Percona plugin. MariaDB by default stores as a flat file (CSV) . These flat file can made to Elastic Search ( ELK with Percona Plugin ).

These Audit logs can be used for HIPPA,PCI, etc compliances.

2 thoughts on “Integrating MariaDB Audit plugin in MySQL 5.7

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s