In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to use the Audit plug-in in the MySQL database. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
How to use the MySQL database Audit plug-in
The related code is as follows:
Sql/sql_audit.cc
This file defines the interface function for the audit plug-in.
Sql/sql_audit.h
Declare the function and define the function mysql_audit_general_log, which is called first when audit is triggered.
Plugin/audit_null/audit_null.c
This is a template program that gives the interface that the most basic audit plug-in needs to define.
In order to implement a complete audit program, it needs to include the plug-in initialization, the main function, and the calling function after uninstalling the plug-in. Here we take audit_null.c as an example:
Staticintaudit_null_plugin_init (void*arg__attribute__ ((unused)
This function is called when the plug-in is installed, which is mainly used to do some initialization work, such as initializing global variables.
Staticvoidaudit_null_notify (MYSQL_THDthd,unsignedintevent_class,constvoid*event)
This is the main function of the audit plug-in, which will be called when the corresponding event is triggered, and the parameters include:
Thd: the thread that triggered this function, which contains a wealth of information in the structure THD, so that many interesting functions can be implemented.
Event_class/event: the former indicates the type of event, which is used to determine the type of the third parameter event structure. It is defined by macros. A value of MYSQL_AUDIT_GENERAL_CLASS indicates that it is triggered by the action of operating the database. A value of MYSQL_AUDIT_CONNECTION_CLASS means that it is triggered by initiating a database connection. For different types, different interface functions are called to trigger audit.
Staticaudit_handler_taudit_handlers [] = {general_class_handler,connection_class_handler}
What are the tips for using the MySQL database Audit plug-in
For the above two cases, it will be subdivided into multiple event types, which are defined in the file plugin_audit.h
1. When initiating a connection
# defineMYSQL_AUDIT_CONNECTION_CONNECT0
Triggered after completion of authentication
# defineMYSQL_AUDIT_CONNECTION_DISCONNECT1
Triggered when the connection is interrupted
# defineMYSQL_AUDIT_CONNECTION_CHANGE_USER2
Triggered after the COM_CHANGE_USER command is executed.
The structure of the event parameter is: mysql_event_connection.
two。 When operating the database
# defineMYSQL_AUDIT_GENERAL_LOG0
Triggered before it is submitted to generalquerylog
# defineMYSQL_AUDIT_GENERAL_ERROR1
Triggered before an error is sent to the user
# defineMYSQL_AUDIT_GENERAL_RESULT2
Triggered when the result set is sent to the user
# defineMYSQL_AUDIT_GENERAL_STATUS3
Triggered when a result set is sent or an error occurs. The structure of the event parameter is: mysql_event_general.
No matter which event structure is, the above seven event types are recorded in it, and we can write plug-in code according to different event types.
3.staticintaudit_null_plugin_deinit (void*arg__attribute__ ((unused)
This function is called when the plug-in is uninstalled and can be used to perform operations such as releasing resources, closing files, and so on.
4. Define the descriptor structure of the plug-in:
Structst_mysql_audit {intinterface_version;void (* release_thd) (MYSQL_THD); void (* event_notify) (MYSQL_THD,unsignedint,constvoid*); unsignedlongclass_ Mask [MySQL _ AUDIT_CLASS_MASK_SIZE];}
Version. The value is generally MYSQL_AUDIT_INTERFACE_VERSION.
Release_thd, generally set to NULL.
Event_notify, the main handler, is called when certain events occur (audit_null_notify).
Class_mask, mask.
Release_thd and event_notify can be used together. When the event triggers event_notify, the plug-in cannot uninstall. When the call is completed, the server will notify the release_thd function. In this way, we can allocate resources in event_notify and release them uniformly in release_thd.
5. Defines a statues variable that specifies which values are displayed when SHOWSTATIS is called
Staticstructst_mysql_show_varaudit_null_status []
6. Library descriptor for the plug-in
Mysql_declare_plugin (audit_null) {MYSQL_AUDIT_PLUGIN,/*type*/&audit_null_descriptor,/*descriptor*/ "NULL_AUDIT" / * name*/ "OracleCorp", / * author*/ "SimpleNULLAudit", / * description*/PLUGIN_LICENSE_GPL,audit_null_plugin_init,/*initfunction (whenloaded) * / audit_null_plugin_deinit,/*deinitfunction (whenunloaded) * /
The third field, "NULL_AUDIT", is the name of the plug-in when the INSTALLPLUGIN is executed. If it is inconsistent, the error that the symbol cannot be found in the library file is not reported.
Summary:
Audit plug-ins can be triggered by a variety of events, so when the server is busy, you need to write code carefully to prevent too much extra overhead to affect the overall performance of the server.
On how to use the Audit plug-in in the MySQL database to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.