MySQL Percona Server 5.5 installation Audit plugin

Source: Internet
Author: User
Tags percona percona server

In the near future, the company requires an audit of the operation on the MySQL database; the Audit_log Audit plugin is integrated in the MySQL official Enterprise Edition (paid edition).
However, this plugin is not included in the community open source version and is not available for download.
Learn more about MariaDB has an audit plugin called server_audit.so, which is rumored to have been independently downloaded previously.
But I did not find the download link on the official website, simply download a mariadb 5.5.50 binary installation package, extract a server_audit.so file from it,

1. Log in to the database and view the Plugin_dir directory
Mysql> SHOW GLOBAL VARIABLES like ' plugin_dir ';
+---------------------+---------------------------------------------------------------------------------------- -+
| variable_name | Value |
+---------------------+---------------------------------------------------------------------------------------- --+
| Plugin_dir | /usr/local/percona-server-5.5.33-rel31.1-566.linux.x86_64/lib/mysql/plugin/|
+---------------+---------------------------------------------------------------------------------------------- --+
1 row in Set (0.00 sec)


2. Move the server_audit.so to the plugin directory, and then modify the file authorization
MV server_audit.so/usr/local/percona-server-5.5.33-rel31.1-566.linux.x86_64/lib/mysql/plugin/
Chown mysql.mysql/usr/local/percona-server-5.5.33-rel31.1-566.linux.x86_64/lib/mysql/plugin/server_audit.so
chmod 755/usr/local/percona-server-5.5.33-rel31.1-566.linux.x86_64/lib/mysql/plugin/server_audit.so


3. Load and install the plugin
mysql> Install plugin server_audit SONAME ' server_audit.so ';
Query OK, 0 rows affected (0.02 sec)
No need to restart MySQL service!
Mysql> select * from Mysql.plugin;
+---------------+--------------------+
| name | DL |
+---------------+--------------------+
| Server_audit | server_audit.so |
+---------------+--------------------+
1 row in Set (0.00 sec)


Another way to install it is to modify the configuration and need to restart the MySQL service to take effect
[Mysqld]
Plugin-load=server_audit=server_audit.so
Restart the MySQL service!
This type of installation does not generate records in Mysql.plugin
Mysql> select * from Mysql.plugin;
Empty Set (0.00 sec)

4. Review the relevant variables for Server_audit and enable the auditing function
Mysql> show global variables like '%server_audit% ';
+----------------------------------+----------------------------+
| variable_name | Value |
+----------------------------------+----------------------------+
|                                  server_audit_events | |
|                                 Server_audit_excl_users | |
| Server_audit_file_path | Server_audit.log |
| Server_audit_file_rotate_now | OFF |
| Server_audit_file_rotate_size | 1000000 |
| server_audit_file_rotations | 9 |
|                                 Server_audit_incl_users | |
| Server_audit_loc_info | oooooooooo |
| server_audit_logging | OFF |
| Server_audit_mode | 1 |
| Server_audit_output_type | File |
| Server_audit_query_log_limit | 1024 |
| server_audit_syslog_facility | Log_user |
| server_audit_syslog_ident | mysql-server_auditing |
|                                  Server_audit_syslog_info | |
| server_audit_syslog_priority | Log_info |
+-------------------------------+--------------------------------+
Rows in Set (0.00 sec)


Server_audit_logging the definition is open,
Server_audit_events defines the relevant events

Common audit events have CONNECTION,QUERY,TABLE,QUERY_DDL,QUERY_DML
Assume that you now need to audit query execution.

mysql> set global server_audit_events= ' QUERY ';
Query OK, 0 rows Affected (0.00 sec)

mysql> set global server_audit_logging= ' on ';
Query OK, 0 rows Affected (0.00 sec)

5. Perform the query operation on the database, you can see the detailed record information in the Server_audit.log, the Server_audit.log file is located in the DataDir directory by default.

20160811 16:11:40,ouzhou158,root,localhost,1872,7,query,, ' SHOW GLOBAL VARIABLES like ' plugin_dir\ ', 0

Corresponding time, server name, user name of published SQL, host, connection number, operation type, statement text and query execution succeeded

For an audit-related option description, refer to the link below
https://mariadb.com/kb/en/mariadb/server_audit-system-variables/

MySQL Percona Server 5.5 installation Audit plugin

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.