検索
ホームページデータベースmysql チュートリアルMySQL Audit Plugin now available in Percona Server 5.5 and 5_MySQL

The MySQL Audit Plugin is now available for free in Percona ServerThe newPercona Server 5.5.37-35.0andPercona Server 5.6.17-65.0-56, announced yesterday (May 6), both include the open source version of the MySQL Audit Plugin. The MySQL Audit Plugin is used to log all queries or connections (“audit” MySQL usage). Until yesterday’s release, the MySQL Audit Plugin was only available inMySQL Enterprise.

Logging all MySQL usage is very important for a number of applications, for example:

  • Required: applications which deals with sensitive data (credit cards, medical records, etc); required for security compliances (i.e. HIPAA)
  • Very helpful: multi-tenants applications or MySQL as a service; MySQL administrators can audit the MySQL usage from the security and performance standpoint
  • Very helpful: investigating and troubleshooting; it is great to have a full log ofall queries, which can help a lot for troubleshooting of MySQL and even for performance audit.

Originally, the only “easy” option was toenable general log. (Other options included using binary logs which does not include select queries or enabling queries “trace” in the application or MySQL connector). However, logging all queries using a general log may dramatically decrease performance in the highly loaded MySQL applications: Aleksandr Kuzminsky published a benchmark in 2009 to showthe overhead of MySQL general and slow log. The main benefit of MySQL Log Audit plugin is that it logs all queriesasynchronously(can be changed in the config). I’ve decided to try the new audit plugin in Percona Server and measure the performance impact of the new plugin compared to enabling the general log for the CPU bound applications.

How to start with MySQL Audit Plugin

First, we will need to enable (or “install”) MySQL audit plugin asdecribed in the doc:

mysql> select version();+-------------+| version() |+-------------+| 5.5.37-35.0 |+-------------+1 row in set (0.00 sec)mysql> INSTALL PLUGIN audit_log SONAME 'audit_log.so';Query OK, 0 rows affected (0.00 sec)

mysql>selectversion();

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

|version()  |

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

|5.5.37-35.0

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

1rowinset(0.00

mysql>INSTALL PLUGINaudit_logSONAME'audit_log.so';

QueryOK,0rowsaffected

Now can see all MySQL audit plugin options:

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 |+--------------------------+--------------+8 rows in set (0.00 sec)

mysql>showglobalvariableslike'%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      |

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

8rowsinset(0.00

There are a bunch of options we can tweak here, the most important for MySQL performance are:

  • audit_log_buffer_size; this buffer is used to cache the queries (for asynchronous operation).
  • audit_log_strategy; All options are listed in the documentation page:
Value Meaning
ASYNCHRONOUS Log asynchronously, wait for space in output buffer
PERFORMANCE Log asynchronously, drop request if insufficient space in output buffer
SEMISYNCHRONOUS Log synchronously, permit caching by operating system
SYNCHRONOUS Log synchronously, call sync() after each request

The most useful option in my mind is ASYNCHRONOUS, providing us with good balance between performance and not loosing transactions if the output buffer is not large enough.

  •  audit_log_policy; we can log all queries or MySQL logins only (very useful if we only need to audit MySQL connections)

Open Source Audit Plugin in MySQL Community server

You can also use Percona Open Source version of Audit Plugin in MySQL community version (5.5.37 and 5.6.17). Simply download the linux tarball of Percona Server and copy the  audit_log.so to your MySQL plugin dir.

Find plugin dir:

mysql> show global variables like '%plugin%';+---------------+------------------------------+| Variable_name | Value|+---------------+------------------------------+| plugin_dir| /usr/local/mysql/lib/plugin/ |+---------------+------------------------------+1 row in set (0.00 sec)

mysql>showglobalvariableslike'%plugin%';

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

|Variable_name|Value                        |

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

|plugin_dir    |/usr/local/mysql/lib/plugin/

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

1rowinset(0.00

Copy the file:

# cp audit_log.so /usr/local/mysql/lib/plugin/

# cp audit_log.so /usr/local/mysql/lib/plugin/

Install plugin:

Server version: 5.5.37 MySQL Community Server (GPL)mysql> INSTALL PLUGIN audit_log SONAME 'audit_log.so';Query OK, 0 rows affected (0.00 sec)Server version: 5.6.17 MySQL Community Server (GPL)mysql> INSTALL PLUGIN audit_log SONAME 'audit_log.so';Query OK, 0 rows affected (0.00 sec)

Serverversion:5.5.37MySQLCommunityServer(GPL)

mysql>INSTALLPLUGINaudit_logSONAME'audit_log.so';

QueryOK,0rowsaffected(0.00sec)

Serverversion:5.6.17MySQLCommunityServer(GPL)

mysql>INSTALLPLUGINaudit_logSONAME'audit_log.so';

QueryOK,0rowsaffected(0.00sec)

Using MySQL audit plugin

When plugin is enabled, it will log entries in audit.log file in XML format. Example:

<audit_record utc></audit_record><audit_record utc plugin audit_log soname localhost></audit_record><audit_record utc global variables like localhost></audit_record>
  "NAME"="Audit"

  "RECORD"="1_2014-04-30T00:04:42"

  "TIMESTAMP"="2014-04-30T00:04:42 UTC"

  "MYSQL_VERSION"="5.5.37-35.0"

  "STARTUP_OPTIONS"="--basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock"

  "OS_VERSION"="x86_64-Linux",

/>  "NAME"="Query"

  "RECORD"="2_2014-04-30T00:04:42"

  "TIMESTAMP"="2014-04-30T00:04:42 UTC"

  "COMMAND_CLASS"="install_plugin"

  "CONNECTION_ID"="1"

  "STATUS"="0"

  "SQLTEXT"="INSTALL PLUGIN audit_log SONAME 'audit_log.so'"

  "USER"="root[root] @ localhost []"

  "HOST"="localhost"

  "OS_USER"=""  "IP"=""/>  "NAME"="Query"

  "RECORD"="3_2014-04-30T00:04:42"

  "TIMESTAMP"="2014-04-30T00:05:07 UTC"

  "COMMAND_CLASS"="show_variables"

  "CONNECTION_ID"="1"

  "STATUS"="0"

  "SQLTEXT"="show global variables like '%audit%'"

  "USER"="root[root] @ localhost []"

  "HOST"="localhost"

  "OS_USER"=""  "IP"=""/>

<audit_record utc all on sbtest. to sb identified by localhost></audit_record><audit_record utc></audit_record><audit_record utc pad from sbtest8 where id='5036031"' localhost></audit_record>
  "NAME"="Query"

  "RECORD"="10_2014-04-30T00:04:42"

  "TIMESTAMP"="2014-04-30T12:33:20 UTC"

  "COMMAND_CLASS"="grant"

  "CONNECTION_ID"="2"

  "STATUS"="0"

  "SQLTEXT"="grant all on sbtest.* to sb@localhost identified by 'sb'"

  "USER"="root[root] @ localhost []"

  "HOST"="localhost"

  "OS_USER"=""  "IP"=""/>  "NAME"="Connect"

  "RECORD"="11_2014-04-30T00:04:42"

  "TIMESTAMP"="2014-04-30T12:34:53 UTC"

  "CONNECTION_ID"="3"

  "STATUS"="0"  "USER"="sb"

  "PRIV_USER"="sb"

  "OS_LOGIN"=""

  "PROXY_USER"=""

  "HOST"="localhost"

  "IP"=""

  "DB"="sbtest"

/>"RECORD"="1292_2014-04-30T00:04:42"

"TIMESTAMP"="2014-04-30T12:45:07 UTC"

"COMMAND_CLASS"="select"

"CONNECTION_ID"="32"

"STATUS"="1146"

"SQLTEXT"="SELECT pad FROM sbtest8 WHERE id=5036031"

"USER"="sb[sb] @ localhost []"

"HOST"="localhost"

"OS_USER"="""IP"=""/>

 Important notes: 

  • As all queries will be logged here, the passwords from “GRANT” will also be saved in clear text (as you can see above). It is very important to secure the file on disk.
  • The file can grow very large on disk:
ls -lah /var/lib/mysql/audit.log-rw-rw---- 1 mysql mysql 7.1G May 4 07:30 /var/lib/mysql/audit.log

ls-lah/var/lib/mysql/audit.log

-rw-rw----1mysqlmysql7.1GMay407:30/var/lib/mysql/audit.log

Searching the Audit Log entries

MySQL utilities provide a useful tool, mysqlauditgrep, to search / grep the logs file.  Unfortunately, I was not able to make it work (tried both v. 1.3 and v 1.4)  with audit plugin format created by Percona server. According tothis bug  it can’t parse the “new” audit format. In my case, mysqlauditgrep will return a parsing error when I use the default format and returned no results when I set the “audit_log_format=NEW”. It will be nice to use the mysqlauditgrep as it looks like a very powerful tool, but for now our searching options are limited to conventional linux grep (which is not very easy for XML documents) or custom application to parse/search XML.

Performance overhead of Audit Log Plugin and General Log 

Finally, I wanted to measure the overhead of the Audit Log Plugin compared to General Log. I did a quick benchmark withsysbenchOLTP test (CPU bound workload) with 4 modes:

  1. Audit Plugin disabled (to measure baseline)
  2. Audit Plugin enabled and logs all queries
  3. Audit Plugin enabled and logs only logins
  4. General Log enabled, Audit Plugin disabled

Here are the results:

Test Overhead
Plugin +  audit_log_policy = ALL ~15% overhead
Plugin +  audit_log_policy = LOGINS ~0% overhead (sysbench only connects once, so there may be bigger overhead here)
General_log ~62% overhead

As we can see here, audit log is not free from overhead, however, it is much smaller than enabling general_log to log all and every query. Those are quick benchmark results and more tests are need for more accurate measurements. Also, as always, your milage can vary.

Nice to have features

What I would love to have for audit plugin is the ability to log only some specific actions. For example, only log activity from a specific user or access to a specific table (i.e. a table with a sensitive data), etc. This will give more control and less overhead (=better performance).

Conclusion

The MySQL Audit Plugin is a great feature – it is a valuable tool for MySQL security and performance audits. The performance overhead may be a concern for a highly loaded systems, however, it looks reasonable and is much better than using general log to log all queries.

If you use general log or any other audit plugins, please share your experience in the comments.

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
InnoDBバッファープールとそのパフォーマンスの重要性を説明してください。InnoDBバッファープールとそのパフォーマンスの重要性を説明してください。Apr 19, 2025 am 12:24 AM

Innodbbufferpoolは、データをキャッシュしてページをインデックス作成することにより、ディスクI/Oを削減し、データベースのパフォーマンスを改善します。その作業原則には次のものが含まれます。1。データ読み取り:Bufferpoolのデータを読む。 2。データの書き込み:データを変更した後、bufferpoolに書き込み、定期的にディスクに更新します。 3.キャッシュ管理:LRUアルゴリズムを使用して、キャッシュページを管理します。 4.読みメカニズム:隣接するデータページを事前にロードします。 BufferPoolのサイジングと複数のインスタンスを使用することにより、データベースのパフォーマンスを最適化できます。

MySQL対その他のプログラミング言語:比較MySQL対その他のプログラミング言語:比較Apr 19, 2025 am 12:22 AM

他のプログラミング言語と比較して、MySQLは主にデータの保存と管理に使用されますが、Python、Java、Cなどの他の言語は論理処理とアプリケーション開発に使用されます。 MySQLは、データ管理のニーズに適した高性能、スケーラビリティ、およびクロスプラットフォームサポートで知られていますが、他の言語は、データ分析、エンタープライズアプリケーション、システムプログラミングなどのそれぞれの分野で利点があります。

MySQLの学習:新しいユーザー向けの段階的なガイドMySQLの学習:新しいユーザー向けの段階的なガイドApr 19, 2025 am 12:19 AM

MySQLは、データストレージ、管理、分析に適した強力なオープンソースデータベース管理システムであるため、学習する価値があります。 1)MySQLは、SQLを使用してデータを操作するリレーショナルデータベースであり、構造化されたデータ管理に適しています。 2)SQL言語はMySQLと対話するための鍵であり、CRUD操作をサポートします。 3)MySQLの作業原則には、クライアント/サーバーアーキテクチャ、ストレージエンジン、クエリオプティマイザーが含まれます。 4)基本的な使用には、データベースとテーブルの作成が含まれ、高度な使用にはJoinを使用してテーブルの参加が含まれます。 5)一般的なエラーには、構文エラーと許可の問題が含まれ、デバッグスキルには、構文のチェックと説明コマンドの使用が含まれます。 6)パフォーマンスの最適化には、インデックスの使用、SQLステートメントの最適化、およびデータベースの定期的なメンテナンスが含まれます。

MySQL:初心者が習得するための必須スキルMySQL:初心者が習得するための必須スキルApr 18, 2025 am 12:24 AM

MySQLは、初心者がデータベーススキルを学ぶのに適しています。 1.MySQLサーバーとクライアントツールをインストールします。 2。selectなどの基本的なSQLクエリを理解します。 3。マスターデータ操作:テーブルを作成し、データを挿入、更新、削除します。 4.高度なスキルを学ぶ:サブクエリとウィンドウの関数。 5。デバッグと最適化:構文を確認し、インデックスを使用し、選択*を避け、制限を使用します。

MySQL:構造化データとリレーショナルデータベースMySQL:構造化データとリレーショナルデータベースApr 18, 2025 am 12:22 AM

MySQLは、テーブル構造とSQLクエリを介して構造化されたデータを効率的に管理し、外部キーを介してテーブル間関係を実装します。 1.テーブルを作成するときにデータ形式と入力を定義します。 2。外部キーを使用して、テーブル間の関係を確立します。 3。インデックス作成とクエリの最適化により、パフォーマンスを改善します。 4.データベースを定期的にバックアップおよび監視して、データのセキュリティとパフォーマンスの最適化を確保します。

MySQL:説明されている主要な機能と機能MySQL:説明されている主要な機能と機能Apr 18, 2025 am 12:17 AM

MySQLは、Web開発で広く使用されているオープンソースリレーショナルデータベース管理システムです。その重要な機能には、次のものが含まれます。1。さまざまなシナリオに適したInnodbやMyisamなどの複数のストレージエンジンをサポートします。 2。ロードバランスとデータバックアップを容易にするために、マスタースレーブレプリケーション機能を提供します。 3.クエリの最適化とインデックスの使用により、クエリ効率を改善します。

SQLの目的:MySQLデータベースとの対話SQLの目的:MySQLデータベースとの対話Apr 18, 2025 am 12:12 AM

SQLは、MySQLデータベースと対話して、データの追加、削除、変更、検査、データベース設計を実現するために使用されます。 1)SQLは、ステートメントの選択、挿入、更新、削除を介してデータ操作を実行します。 2)データベースの設計と管理に作成、変更、ドロップステートメントを使用します。 3)複雑なクエリとデータ分析は、ビジネス上の意思決定効率を改善するためにSQLを通じて実装されます。

初心者向けのMySQL:データベース管理を開始します初心者向けのMySQL:データベース管理を開始しますApr 18, 2025 am 12:10 AM

MySQLの基本操作には、データベース、テーブルの作成、およびSQLを使用してデータのCRUD操作を実行することが含まれます。 1.データベースの作成:createdatabasemy_first_db; 2。テーブルの作成:createTableBooks(idintauto_incrementprimarykey、titlevarchary(100)notnull、authorvarchar(100)notnull、published_yearint); 3.データの挿入:InsertIntoBooks(タイトル、著者、公開_year)VA

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境