찾다
데이터 베이스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으로 문의하세요.
MySQL에서 느린 쿼리를 식별하고 최적화하는 방법은 무엇입니까? (느린 쿼리 로그, Performance_schema)MySQL에서 느린 쿼리를 식별하고 최적화하는 방법은 무엇입니까? (느린 쿼리 로그, Performance_schema)Apr 10, 2025 am 09:36 AM

MySQL 느린 쿼리를 최적화하려면 SlowQueryLog 및 Performance_Schema를 사용해야합니다. 1. SlowQueryLog 및 Set Stresholds를 사용하여 느린 쿼리를 기록합니다. 2. Performance_schema를 사용하여 쿼리 실행 세부 정보를 분석하고 성능 병목 현상을 찾고 최적화하십시오.

MySQL 및 SQL : 개발자를위한 필수 기술MySQL 및 SQL : 개발자를위한 필수 기술Apr 10, 2025 am 09:30 AM

MySQL 및 SQL은 개발자에게 필수적인 기술입니다. 1.MySQL은 오픈 소스 관계형 데이터베이스 관리 시스템이며 SQL은 데이터베이스를 관리하고 작동하는 데 사용되는 표준 언어입니다. 2.MYSQL은 효율적인 데이터 저장 및 검색 기능을 통해 여러 스토리지 엔진을 지원하며 SQL은 간단한 문을 통해 복잡한 데이터 작업을 완료합니다. 3. 사용의 예에는 기본 쿼리 및 조건 별 필터링 및 정렬과 같은 고급 쿼리가 포함됩니다. 4. 일반적인 오류에는 구문 오류 및 성능 문제가 포함되며 SQL 문을 확인하고 설명 명령을 사용하여 최적화 할 수 있습니다. 5. 성능 최적화 기술에는 인덱스 사용, 전체 테이블 스캔 피하기, 조인 작업 최적화 및 코드 가독성 향상이 포함됩니다.

MySQL 비동기 마스터 슬레이브 복제 프로세스를 설명하십시오.MySQL 비동기 마스터 슬레이브 복제 프로세스를 설명하십시오.Apr 10, 2025 am 09:30 AM

MySQL 비동기 마스터 슬레이브 복제는 Binlog를 통한 데이터 동기화를 가능하게하여 읽기 성능 및 고 가용성을 향상시킵니다. 1) 마스터 서버 레코드는 Binlog로 변경됩니다. 2) 슬레이브 서버는 I/O 스레드를 통해 Binlog를 읽습니다. 3) 서버 SQL 스레드는 데이터를 동기화하기 위해 Binlog를 적용합니다.

MySQL : 쉽게 학습하기위한 간단한 개념MySQL : 쉽게 학습하기위한 간단한 개념Apr 10, 2025 am 09:29 AM

MySQL은 오픈 소스 관계형 데이터베이스 관리 시스템입니다. 1) 데이터베이스 및 테이블 작성 : CreateAbase 및 CreateTable 명령을 사용하십시오. 2) 기본 작업 : 삽입, 업데이트, 삭제 및 선택. 3) 고급 운영 : 가입, 하위 쿼리 및 거래 처리. 4) 디버깅 기술 : 확인, 데이터 유형 및 권한을 확인하십시오. 5) 최적화 제안 : 인덱스 사용, 선택을 피하고 거래를 사용하십시오.

MySQL : 데이터베이스에 대한 사용자 친화적 인 소개MySQL : 데이터베이스에 대한 사용자 친화적 인 소개Apr 10, 2025 am 09:27 AM

MySQL의 설치 및 기본 작업에는 다음이 포함됩니다. 1. MySQL 다운로드 및 설치, 루트 사용자 비밀번호를 설정하십시오. 2. SQL 명령을 사용하여 CreateAbase 및 CreateTable과 같은 데이터베이스 및 테이블을 만듭니다. 3. CRUD 작업을 실행하고 삽입, 선택, 업데이트, 명령을 삭제합니다. 4. 성능을 최적화하고 복잡한 논리를 구현하기 위해 인덱스 및 저장 절차를 생성합니다. 이 단계를 사용하면 MySQL 데이터베이스를 처음부터 구축하고 관리 할 수 ​​있습니다.

InnoDB 버퍼 풀은 어떻게 작동하며 성능에 중요한 이유는 무엇입니까?InnoDB 버퍼 풀은 어떻게 작동하며 성능에 중요한 이유는 무엇입니까?Apr 09, 2025 am 12:12 AM

innodbbufferpool은 데이터와 색인 페이지를 메모리에로드하여 MySQL 데이터베이스의 성능을 향상시킵니다. 1) 데이터 페이지가 버퍼 풀에로드되어 디스크 I/O를 줄입니다. 2) 더러운 페이지는 정기적으로 디스크로 표시되고 새로 고침됩니다. 3) LRU 알고리즘 관리 데이터 페이지 제거. 4) 읽기 메커니즘은 가능한 데이터 페이지를 미리로드합니다.

MySQL : 초보자를위한 데이터 관리의 용이성MySQL : 초보자를위한 데이터 관리의 용이성Apr 09, 2025 am 12:07 AM

MySQL은 설치가 간단하고 강력하며 데이터를 쉽게 관리하기 쉽기 때문에 초보자에게 적합합니다. 1. 다양한 운영 체제에 적합한 간단한 설치 및 구성. 2. 데이터베이스 및 테이블 작성, 삽입, 쿼리, 업데이트 및 삭제와 같은 기본 작업을 지원합니다. 3. 조인 작업 및 하위 쿼리와 같은 고급 기능을 제공합니다. 4. 인덱싱, 쿼리 최적화 및 테이블 파티셔닝을 통해 성능을 향상시킬 수 있습니다. 5. 데이터 보안 및 일관성을 보장하기위한 지원 백업, 복구 및 보안 조치.

MySQL에서 인덱스를 사용하는 것보다 전체 테이블 스캔이 더 빠를 수 있습니까?MySQL에서 인덱스를 사용하는 것보다 전체 테이블 스캔이 더 빠를 수 있습니까?Apr 09, 2025 am 12:05 AM

전체 테이블 스캔은 MySQL에서 인덱스를 사용하는 것보다 빠를 수 있습니다. 특정 사례는 다음과 같습니다. 1) 데이터 볼륨은 작습니다. 2) 쿼리가 많은 양의 데이터를 반환 할 때; 3) 인덱스 열이 매우 선택적이지 않은 경우; 4) 복잡한 쿼리시. 쿼리 계획을 분석하고 인덱스 최적화, 과도한 인덱스를 피하고 정기적으로 테이블을 유지 관리하면 실제 응용 프로그램에서 최상의 선택을 할 수 있습니다.

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 Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

SublimeText3 영어 버전

SublimeText3 영어 버전

권장 사항: Win 버전, 코드 프롬프트 지원!

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는