How can the audit log be enabled in MySQL?
To enable MySQL’s auditing feature, you can follow these steps:
- Edit the MySQL configuration file my.cnf or my.ini, and add the following configuration in the [mysqld] section:
[mysqld]
...
# 开启日志审计
log-output=FILE
general-log=1
general-log-file=/path/to/general.log
Among them, log-output specifies the logging output method as a file, general-log indicates the general query log is enabled, and general-log-file specifies the log file path.
- Restart the MySQL service to apply the configuration changes.
- To view the log file, you can use either a command line tool or a text editor to open the specified log file /path/to/general.log and view the audit information of MySQL.
It should be noted that enabling logging audit function will generate a large amount of log information, which may impact system performance and disk space. In a production environment, it is recommended to selectively enable the corresponding log types based on needs and actual situations, and regularly clean up log files.