RDS MySQL Audit Logging Setup
Purpose: Enable logging in RDS MySQL for auditing and troubleshooting. This allows you to track which user executed which query and monitor slow or general queries.Steps:
1. Create or Modify a Custom DB Parameter Group- Create or use an existing custom DB parameter group for your RDS MySQL instance.
- Set the following parameters:
| Parameter | Value | Notes |
|---|---|---|
general_log | 1 (ON) | Logs all queries |
slow_query_log | 1 (ON) | Logs queries slower than long_query_time |
audit_log | 1 (ON) | Logs queries via audit plugin |
log_output | TABLE | Stores logs in MySQL tables |
long_query_time | 0.5–1 | Threshold for slow queries (adjust as needed) |
- Attach the parameter group to your DB instance.
- Reboot the RDS instance for changes to take effect.
2. View General Query Log
- General queries are stored in the
mysql.general_logtable. - Format of
user_hostcolumn:username[username] @ [IP] - Retrieve last queries executed by a specific user:
Replaceusernamewith the MySQL username.CONVERT(argument USING utf8)converts hex-encoded queries to readable SQL.
3. View Slow Queries
- Use this to identify queries exceeding the
long_query_timethreshold.
4. View Audit Log Queries
- Shows all queries executed by the user via the audit plugin.
- Useful for auditing and compliance purposes.
5. Notes
- Queries executed before enabling logging will not appear in logs.
- Using TABLE logging makes queries easy to inspect but logs can grow fast.
- Periodically truncate logs to save space:
