Implement MySQL with Docker in Anypoint Code Builder (ACB)
- Alex Martinez

- Jul 28, 2025
- 4 min read
In this tutorial, you’ll learn how to connect a MySQL database running in Docker to a MuleSoft project in Anypoint Code Builder (ACB) — all inside VS Code, without ever leaving your IDE.
We’ll use three powerful VS Code extensions:
Container Tools → run MySQL with a single click
Database Client → create tables and test queries
Postcode → test your API endpoints
By the end, you’ll have a Mule flow that returns live MySQL data in JSON.
Follow up with the GitHub repo: https://github.com/alexandramartinez/todo-api-impl
🎥 Prefer video? Watch the full tutorial here:
Prerequisites
Make sure you already have:
An Anypoint Code Builder project scaffolded
VS Code with the following extensions installed:
Anypoint Extension Pack
Container Tools
Database Client
Postcode
Docker Desktop running
Step 1: Launch MySQL with Container Tools
In your project folder, create a file called docker-compose.yml and paste this in:
Click on the Run All Services button inside this file (you have to have the Containers extension for VS Code)
✅ MySQL is now running inside a Docker container.
Step 2: Connect Using the Database Client Extension
Open the Database panel in VS Code.
Click + New Connection and select MySQL.
Enter:
Host: 127.0.0.1
Port: 3306
User: user
Password: password
Database: mysqldb
Save and test the connection — you should see it succeed.
Run the following SQL to create your table:
✅ The table is ready — no data inserted yet.
Step 3: Implement the get-all-tasks Sub-Flow in ACB
Now that the database is running and the table is created, let’s implement the flow that will fetch tasks from MySQL.
In your scaffolded Mule project, add the following sub-flow to your implementation XML file (for example: get-all-tasks.xml):
How This Sub-Flow Works
Start Logger - Marks the beginning of the flow. This is helpful for debugging and tracking execution in your logs.
Build the SQL Query - Uses a DataWeave script (dw/get-all-tasks-request.dwl) to generate the SQL query dynamically. This keeps SQL logic separate from the flow.
Database Select - Executes the SQL query against MySQL using the connection defined in Mysql_Database_Config.
#[payload] tells Mule to use the SQL string produced by the previous step.
Transform DB Results to JSON - Applies a second DataWeave script (dw/get-all-tasks-response.dwl) to shape the raw DB results into a clean JSON response for the API.
End Logger - Marks the successful completion of the sub-flow.
Here are the two DataWeave script files:
Step 4: Run and Test with Postcode
Start your Mule app from ACB.
Open the Postcode extension in VS Code.
Create a new request:
GET http://localhost:8081/api/tasksClick Send
✅ You’ll see an empty JSON array ([]) until you insert rows later — but your flow is working and ready for data.
Final Thoughts
You’ve successfully implemented a MySQL-backed flow in Anypoint Code Builder using Docker and VS Code extensions.
Container Tools handles your database with one click
Database Client makes schema management simple
Postcode keeps testing inside VS Code
⚡ Next step: Add a POST /tasks flow to insert new tasks into your database!
🔔 Want More Tutorials?
Subscribe to ProstDev on YouTube for weekly videos on:
Anypoint Code Builder (ACB)
API design and implementation
MUnit testing
MuleSoft best practices
🤖 FAQ
1. Why should I use Docker for my database in MuleSoft projects?
Docker makes it easy to spin up a clean, isolated database environment without needing a manual install. It ensures consistency across development machines and avoids “works on my machine” issues.
2. Do I need to know Docker commands to follow this approach?
Not necessarily. With the right VS Code extensions (like Container Tools), you can manage containers with simple clicks instead of terminal commands.
3. What’s the benefit of using a Database Client extension instead of an external tool like MySQL Workbench?
Using a Database Client inside VS Code keeps everything in one place. You can manage schemas, run queries, and debug directly alongside your MuleSoft code.
4. How do DataWeave scripts improve database flows?
DataWeave lets you dynamically generate SQL queries and format responses. This makes your flows more flexible, avoids hardcoding, and ensures cleaner separation between logic and data.
5. Is it safe to build SQL queries dynamically with DataWeave?
Yes, as long as you validate and sanitize inputs properly. For production, always guard against SQL injection by using parameters or prepared statements when possible.
6. What are common use cases for integrating MuleSoft flows with a database?
Typical use cases include CRUD operations for APIs, syncing data between systems, generating reports, or validating user information during API requests.
7. How do I test MuleSoft endpoints without leaving VS Code?
You can use REST client extensions like Postcode. They let you send HTTP requests and view responses without switching to external tools.
8. Why should I separate request and response transformations into different DataWeave files?
This improves maintainability. If your SQL logic or JSON response format changes, you only need to update the relevant .dwl file without touching the main flow.
9. What’s the advantage of using sub-flows in MuleSoft projects?
Sub-flows let you break down complex logic into reusable, modular components. This improves readability, makes testing easier, and allows you to reuse common logic across multiple flows without duplicating code.
10. Can I reuse this approach with other databases besides MySQL?
Absolutely. You can adapt the same setup for PostgreSQL, Oracle, SQL Server, or any database supported by MuleSoft’s Database connector — just update the Docker image and connector configuration.






I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day! Love to talk about the best how to become SAP build partner.