To install the MySQL plug-in server_audit.so in CentOS 7 system, you can follow the following steps:
- Download the server_audit.so plug-in file:
Visit the official MySQL website or a third-party trusted source and download the server_audit.so plug-in file for your MySQL version. Make sure to select the file that matches your MySQL version and architecture (32-bit or 64-bit). -
Copy the plug-in file to the MySQL plug-in directory:
Copy the downloaded server_audit.so plug-in file to the MySQL plug-in directory. By default, the MySQL plugin directory is located/usr/lib64/mysql/plugin/
.sudo cp /path/to/server_audit.so /usr/lib64/mysql/plugin/
-
Modify the MySQL configuration file:
Edit the MySQL configuration filemy.cnf
ormy.ini
add the server_audit plug-in configuration.sudo vi /etc/my.cnf
Add the following at the end of the file:
# 配置server_audit插件 server_audit_logging=ON server_audit_events=CONNECT,QUERY server_audit_file_path=/var/log/mysql/audit.log
server_audit_logging=ON
It means turning on the server_audit plug-in andserver_audit_events
specifying the event type to be recorded. The above configuration means recording user connection events and SQL query events.server_audit_file_path
Specify the storage path of the log file and ensure that the path is writable by the MySQL process. -
Create the log file directory and set permissions:
Create the specified log file directory and set the correct permissions for the MySQL process.sudo mkdir /var/log/mysql sudo chown mysql:mysql /var/log/mysql
-
Restart the MySQL service:
After completing the above steps, restart the MySQL service to make the configuration take effect.sudo systemctl restart mysqld
Now, the MySQL plugin server_audit.so has been successfully installed and configured to log user connection and SQL query events. You can /var/log/mysql/audit.log
view and analyze these events in . Please note, make sure you obtain the server_audit.so plugin file from a trustworthy source and make appropriate configuration and permission settings to ensure system security and stability.