搜尋
首頁資料庫mysql教程Introduction to the Percona MySQL Audit Log Plugin_MySQL

Percona has developed a MySQL Audit Log plugin that is now included in Percona Server since the recent5.5and5.6releases. This implementation is alternative to the MySQL Enterprise Audit Log Plugin: Percona re-implemented the Audit Plugin code as GPL as Oracle’s code was closed source. This post is a quick introduction to this plugin.

Installation
There are two ways to install the Percona MySQL Audit Plugin:

INSTALL PLUGIN audit_log SONAME 'audit_log.so';

INSTALL PLUGINaudit_logSONAME'audit_log.so';

or in my.cnf

[mysqld]plugin-load="audit_log=audit_log.so"
[mysqld]

plugin-load="audit_log=audit_log.so"

Verify installation

mysql> SHOW PLUGINS/G...*************************** 38. row ***************************  Name: audit_logStatus: ACTIVE  Type: AUDITLibrary: audit_log.soLicense: GPL38 rows in set (0.00 sec)

mysql>SHOWPLUGINS/G

...

***************************38.row***************************

  Name:

Status:  Type:

Library:

License:

38rowsinset(0.00

Configuration
Let’s see variables provided by the Percona MySQL Audit Plugin:

mysql> show global variables like 'audit%';+--------------------------+--------------+| Variable_name            | Value        |+--------------------------+--------------+| audit_log_buffer_size    | 1048576      || audit_log_file           | audit.log    || audit_log_flush          | OFF          || audit_log_format         | OLD          || audit_log_policy         | ALL          || audit_log_rotate_on_size | 0            || audit_log_rotations      | 0            || audit_log_strategy       | ASYNCHRONOUS |+--------------------------+--------------+7 rows in set (0.00 sec)

mysql>showglobalvariableslike'audit%';

+--------------------------+--------------+

|Variable_name           |Value       |

+--------------------------+--------------+

|

|audit_log_file          |audit.log   |

|

|

|audit_log_policy        |ALL         |

|

|

|

+--------------------------+--------------+

7rowsinset(0.00

The Percona MySQL Audit Plugin can log using the memory buffer to deliver better performance. Messages will be written into memory buffer first and then flushed to file in background. A certain amount of events can be lost in case of server crash or power outage. Another option is to log directly to file without using memory buffer. There is also an option to fsync every event.

Set audit_log_strategy to control log flushing:

  • ASYNCHRONOUS log using memory buffer, do not drop events if buffer is full
  • PERFORMANCE log using memory buffer, drop events if buffer is full
  • SEMISYNCHRONOUS log directly to file, do not fsync every event
  • SYNCHRONOUS log directly to file, fsync every event

audit_log_buffer_size specifies the size of memory buffer, it makes sense only for ASYNCHRONOUS and PERFORMANCE strategy.

Variable audit_log_file specifies the file to log into. It’s value can be path relative to datadir or absolute path.

The Percona MySQL Audit Plugin can automatically rotate log file based on size. Set audit_log_rotate_size to enable this feature. File is rotated when log grew in size to specified amount of bytes. Set audit_log_rotations to limit the number of log files to keep.

It is possible to log only logins or only queries by setting audit_log_policy value.

Log file format
Lets see how audit records look like

OLD format (audit_log_format = OLD):

<audit_record utc></audit_record>
 "NAME"="Connect"

 "RECORD"="2_2014-04-21T12:34:32"

 "TIMESTAMP"="2014-04-21T12:34:32 UTC"

 "CONNECTION_ID"="1"

 "STATUS"="0" "USER"="root"

 "PRIV_USER"="root"

 "OS_LOGIN"=""

 "PROXY_USER"=""

 "HOST"="localhost"

 "IP"="" "DB"=""/>

NEW format (audit_log_format = NEW):

<audit_record> <name>Connect</name> <record>17481_2014-04-21T12:39:03</record> <timestamp>2014-04-21T12:39:05 UTC</timestamp> <connection_id>4</connection_id> <status>0</status> <user>root</user> <priv_user>root</priv_user> <os_login></os_login> <proxy_user></proxy_user> <host>localhost</host> <ip></ip> <db>test</db></audit_record>

 Connect

 17481_2014-04-21T12:39:03

 2014-04-21T12:39:05 UTC

 4

 0

 root

 root

 

 

 localhost

  test

The difference is that the audit record in the OLD format was written as a single element with attributes, while in the NEW format it is written as a single element with sub-elements.

A good idea of what each sub-element means can be found in Audit Plugin API documentation here:https://dev.mysql.com/doc/refman/5.6/en/writing-audit-plugins.html.

Performance
Lets compare performance of different audit_log_strategy modes. I used readonly sysbench on my laptop for it. Workload is CPU-bound with dataset fit in buffer pool and I set number of sysbench threads to the amount for which count of transactions per seconds is maximum.

sysbench TPS for Percona Audit Log Plugin

I got TPS drop for PERFORMANCE and ASYNCHRONOUS strategies around 7%, 9% for SEMISYNCHRONOUS and 98% for SYNCHRONOUS which shows that syncing every logged statement to disk is not the best thing for performance.

Conclusion
Of course any software has bugs and this plugin has plenty of them. Please give it a try and provide us your feedback. Report any issues here:https://bugs.launchpad.net/percona-server.

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
mysql無法打開共享庫怎麼解決mysql無法打開共享庫怎麼解決Mar 04, 2025 pm 04:01 PM

本文介紹了MySQL的“無法打開共享庫”錯誤。 該問題源於MySQL無法找到必要的共享庫(.SO/.DLL文件)。解決方案涉及通過系統軟件包M驗證庫安裝

減少在Docker中使用MySQL內存的使用減少在Docker中使用MySQL內存的使用Mar 04, 2025 pm 03:52 PM

本文探討了Docker中的優化MySQL內存使用量。 它討論了監視技術(Docker統計,性能架構,外部工具)和配置策略。 其中包括Docker內存限制,交換和cgroups

如何使用Alter Table語句在MySQL中更改表?如何使用Alter Table語句在MySQL中更改表?Mar 19, 2025 pm 03:51 PM

本文討論了使用MySQL的Alter Table語句修改表,包括添加/刪除列,重命名表/列以及更改列數據類型。

在 Linux 中運行 MySQl(有/沒有帶有 phpmyadmin 的 podman 容器)在 Linux 中運行 MySQl(有/沒有帶有 phpmyadmin 的 podman 容器)Mar 04, 2025 pm 03:54 PM

本文比較使用/不使用PhpMyAdmin的Podman容器直接在Linux上安裝MySQL。 它詳細介紹了每種方法的安裝步驟,強調了Podman在孤立,可移植性和可重複性方面的優勢,還

什麼是 SQLite?全面概述什麼是 SQLite?全面概述Mar 04, 2025 pm 03:55 PM

本文提供了SQLite的全面概述,SQLite是一個獨立的,無服務器的關係數據庫。 它詳細介紹了SQLite的優勢(簡單,可移植性,易用性)和缺點(並發限制,可伸縮性挑戰)。 c

在MacOS上運行多個MySQL版本:逐步指南在MacOS上運行多個MySQL版本:逐步指南Mar 04, 2025 pm 03:49 PM

本指南展示了使用自製在MacOS上安裝和管理多個MySQL版本。 它強調使用自製裝置隔離安裝,以防止衝突。 本文詳細詳細介紹了安裝,起始/停止服務和最佳PRA

如何為MySQL連接配置SSL/TLS加密?如何為MySQL連接配置SSL/TLS加密?Mar 18, 2025 pm 12:01 PM

文章討論了為MySQL配置SSL/TLS加密,包括證書生成和驗證。主要問題是使用自簽名證書的安全含義。[角色計數:159]

哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼?哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼?Mar 21, 2025 pm 06:28 PM

文章討論了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比較了它們對初學者和高級用戶的功能和適合性。[159個字符]

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前By尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
1 個月前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中