Before jumping into this article, I highly recommended reading these articles for a better understanding.
If you would like to understand the basics of MuleSoft, refer to these articles before going next:
Open MySQL Workbench to connect the MySQL database; here is the screenshot of my sample database, which I will use in the MuleSoft connector.
Getting Started
First, open Anypoint Studio and Create a New Mule Project.
Enter a project name and selection location and click finish.
Next, add a New Mule Configuration file for global settings.
Next, go to the global.xml file, click the Global Elements tab, and add two config files.
Create a button, select HTTP Listener config, click OK, provide given connection values, test connection, and click OK.
Next, add a new Database config connection.
Enter the required details like config name, Connection, Library, Host, Port, User, Password, and database, and click the test connection and ok button.
Both Global Configuration Elements have been created, and you can edit or delete them from here when needed.
The global configuration is done for HTTP listener; let’s work on Message flow. Drag and drop HTTP Listener from HTTP Palette to Message Flow.
Setup Display Name and select connector configurations and provide endpoint path name.
Now drag and drop Database Select from Mule Palette and enter the display name and Connector configurations, which we create in global configuration and write the query to fetch the data query text.
Next, drag and drop Logger from the Core palette and set a Generic message as Json Payload.
Now, finally setup a Payload. Drag and Drop Set Payload from the Core palette and setup Payload value in Json format.
That’s it. Now run the application.
Open Postman and enter Endpoint to see the output result.
Conclusion
In this article, we learned how to setup a database connector to get MySQL database and display results in Postman.