MySQL Database Block
What it does: Connect your workflow to a MySQL database to read, add, update, or delete data automatically.
In simple terms: MySQL is one of the most popular databases in the world. This block lets your workflow talk to your MySQL database - finding records, adding new ones, making changes, or cleaning up old data.
When to Use This
Use the MySQL block when you need to:
- ✅ Query customer records from your database
- ✅ Save new entries like orders or signups
- ✅ Update existing records based on workflow events
- ✅ Remove outdated or processed entries
- ✅ Pull data for reporting and analysis
- ✅ Keep systems synchronized
Example: When an order is received, save it to MySQL, update inventory counts, and mark the customer as an active buyer.
Key Features
- Read Data: Query tables to find matching records
- Add Data: Insert new rows into your tables
- Update Data: Change existing records with precision
- Delete Data: Remove records you no longer need
- Multiple Tables: Work with any table in your database
- Secure Connection: Connect with encrypted credentials
Setup Guide
Step 1: Add Your Database Connection
Gather these details from your database administrator:
| Setting | What It Is | Example |
|---|---|---|
| Host | Database server address | db.mycompany.com |
| Port | Connection port (default: 3306) | 3306 |
| Database | The database name | ecommerce_db |
| Username | Your database login | app_user |
| Password | Your database password | (keep secure!) |
Security Tip: Use a dedicated database user for your workflows with only the permissions needed. Never use root or admin accounts!
Step 2: Choose Your Operation
Read (SELECT): Find and retrieve data
- Pick the table to query
- Select which columns to return
- Add conditions to filter results
- Sort and limit as needed
Add (INSERT): Create new records
- Choose the target table
- Map your data to table columns
- Records are added automatically
Update (UPDATE): Modify existing records
- Set conditions to find records
- Specify which fields to change
- Only matching records are updated
Delete (DELETE): Remove records
- Set conditions for what to delete
- Only matching records are removed
Step 3: Map Your Data
Connect workflow variables to database columns:
| Workflow Variable | Database Column | Example Value |
|---|---|---|
{{customer.name}} | customer_name | Jane Doe |
{{customer.email}} | email_address | jane@email.com |
{{order.amount}} | total_price | 99.99 |
{{order.date}} | order_date | 2024-01-15 |
Common Use Cases
Store New Orders
When customers place orders through your website or app, automatically save the order details to your MySQL database with timestamps and status tracking.
Customer Lookup
Before processing a request, look up the customer's information, order history, and preferences to personalize the experience.
Inventory Updates
When products are sold or restocked, automatically update inventory counts in your database to keep stock levels accurate.
Generate Reports
Pull sales data, customer statistics, or activity logs from MySQL to create automated reports and dashboards.
User Registration
When new users sign up, store their account information securely in your database with proper timestamps.
What You Get Back
After the block runs, you receive:
- Query Results: The matching rows of data (for read operations)
- Inserted ID: The ID of newly created records
- Rows Affected: Count of records updated or deleted
- Status: Success or failure information
- Error Details: Explanation if something went wrong
Tips for Success
- Always use conditions when updating or deleting to avoid affecting all records
- Test with SELECT first to verify your conditions match the right records
- Map data types correctly - numbers should be numbers, dates should be dates
- Use descriptive column names to make mapping easy and clear
- Include timestamps in your tables for tracking when data changes
Troubleshooting
| Problem | Likely Cause | Solution |
|---|---|---|
| Connection refused | Wrong host/port or firewall | Verify connection settings and network access |
| Access denied | Invalid credentials | Double-check username and password |
| Table not found | Wrong table or database name | Verify table exists in the correct database |
| Data truncated | Value too large for column | Check column sizes match your data |
Best Practices
- Use parameterized queries to prevent security issues
- Create dedicated database users for workflow access
- Enable SSL connections for production databases
- Log all operations for debugging and auditing
- Handle errors gracefully with condition blocks in your workflow