Automated MySQL Database Cleanup for Optimized Performance
detail.loadingPreview
This n8n workflow automates the crucial task of purging old data from your MySQL database. By regularly deleting records older than 30 days, it ensures optimal database performance and frees up valuable storage space. Set it and forget it with a daily scheduled cleanup.
About This Workflow
This n8n workflow provides a robust solution for maintaining the health and efficiency of your MySQL databases. It's designed to automatically remove historical data (specifically records older than 30 days from their stoppedAt timestamp in the execution_entity table) that is no longer needed, preventing database bloat and performance degradation. The setup includes both a manual trigger for immediate cleanup and a daily cron schedule, ensuring continuous, hands-free data hygiene. Ideal for systems like n8n instances where execution history can accumulate, this automation helps enforce data retention policies and keeps your operations running smoothly without manual intervention.
Key Features
- Automated Data Purging: Automatically deletes old records from your MySQL database based on a configurable time threshold.
- Scheduled Execution: Set it to run daily at a specific time (e.g., 7 AM) without manual intervention.
- Manual Trigger Option: Instantly initiate a cleanup whenever needed, providing immediate control.
- Customizable Query: Easily modify the SQL query to target different tables, columns, or data retention periods.
- Database Performance Optimization: Helps improve query speeds and overall database responsiveness by reducing data volume.
How To Use
- MySQL Node Configuration:
- Configure your MySQL credentials named
n8n(or update thecredentialsfield in the MySQL node if you use a different name). - Review the
queryparameter:DELETE FROM execution_entity WHERE DATE(stoppedAt) < DATE_SUB(CURDATE(), INTERVAL 30 DAY). Adjustexecution_entityto your target table and30 DAYto your desired retention period.
- Configure your MySQL credentials named
- Cron Node Configuration:
- The
triggerTimesparameter is currently set to run daily at7AM. Modify thehourvalue to your preferred daily cleanup time.
- The
- Manual Trigger (Optional):
- To execute the purge immediately, simply click the "Execute Workflow" button or manually trigger the "On clicking 'execute'" node in the n8n editor.
- Activate the Workflow:
- Ensure the workflow is set to "Active" to enable the scheduled cron execution.
Apps Used
Workflow JSON
{
"id": "55ca14ec-c1f2-430b-b972-bee82a7f96eb",
"name": "Automated MySQL Database Cleanup for Optimized Performance",
"nodes": 17,
"category": "DevOps",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 55ca14ec-c1f2...
About the Author
AI_Workflow_Bot
LLM Specialist
Building complex chains with OpenAI, Claude, and LangChain.
Statistics
Related Workflows
Discover more workflows you might like
Effortless Bug Reporting: Slack Slash Command to Linear Issue
Streamline your bug reporting process by instantly creating Linear issues directly from Slack using a simple slash command. This workflow enhances team collaboration by providing immediate feedback and a structured approach to logging defects, saving valuable time for development and QA teams.
Automate Qualys Report Generation and Retrieval
Streamline your Qualys security reporting by automating the generation and retrieval of reports. This workflow ensures timely access to crucial security data without manual intervention.
Automated PR Merged QA Notifications
Streamline your QA process with this automated workflow that notifies your team upon successful Pull Request merges. Leverage AI and vector stores to enrich notifications and ensure seamless integration into your development pipeline.