Apicat Docs
  1. Database operations
Apicat Docs
  • What is Apicat?
  • Send requests
    • Create requests
      • Request basics
      • Parameters and body
      • Request headers
      • Request settings
      • Dynamic values
      • HTTP/2
      • SOAP/WebService
    • Authentication and authorization
      • Overview
      • CA and client certificates
      • Authorization types supported by Apidog
      • Digest Auth
      • OAuth 1.0
      • OAuth 2.0
      • Hawk Authentication
      • Kerberos
      • NTLM
      • Akamai EdgeGrid
    • Response and cookies
      • Overview
      • API response in Apidog
      • Create and send cookies
      • Debug requests
    • Dynamic values Modules
      • Airline
      • Animal
      • Color
      • Commerce
      • Company
      • Database
      • Datatype
      • Date
      • Finance
      • Food
      • Git
      • Hacker
      • Helpers
      • Image
      • Internet
      • Location
      • Lorem
      • Music
      • Number
      • Person
      • Phone
      • Science
      • String
      • System
      • Vehicle
      • Word
  • Environments & variables
    • Overview
    • Using variables
    • Environments & services
  • Pre/Post processors
    • Overview
    • Assertion
    • Extract variable
    • Wait
    • Database operations
      • Overview
      • MySQL
      • MongoDB
      • Redis
      • Oracle Client
    • Using scripts
      • Overview
      • Pre processor scripts
      • Post processor scripts
      • Public scripts
      • Postman scripts reference
      • Calling other programming languages
      • Using JS libraries
      • Visualizing responses
      • Script examples
        • Assertion scripts
        • Using variables in scripts
        • Using scripts to modify request messages
        • Other examples
  • Best practices
    • How to handle API signatures
    • How to access OAuth 2.0 protected APIs
    • Apidog collaboration workflow
    • Managing authentication state in Apidog
  • Account & preferences
    • Account settings
    • Generate OpenAPI access token
    • Language settings
    • Hot keys
    • Network proxy configuration
    • Data backup
    • Updating Apidog
    • Deleting account
    • Experimental Features
  • References
    • API-Design First Approach
    • Apidog OpenAPI/Swagger Specificaiton Extensions
    • JSONPath
    • XPath
    • Regular Expressions
    • JSON Schema
    • CSV File Format
    • Install Java Environment
    • Runner deployment environment
    • Apidog flavored Markdown
  1. Database operations

MySQL

MySQL is a widely used relational database management system known for structured data storage, high performance, and strong scalability.
Apidog supports connecting to and interacting with MySQL databases, allowing SQL statements to be executed either before or after an endpoint call.

Connecting to the Database#

1
On the endpoint page, click "Pre/Post Processors" and select "Database Operation".
database-operation.png
2
Click the "Database Connections" dropdown and choose "Manage Database Connection", then click the "+ New" button at the top right corner.
manage-database-connection.png
3
In the popup window, select "MySQL" as the database type and fill in the connection details including host, port, user name, password, and database name. You can store these details in variables and test the connection.
database-connection.png
Apidog suggests that you:
1.
store database connection info in Apidog Cloud for centralized management.
2.
use Vault variables to protect sensitive fields.
3.
avoid storing plaintext credentials in the "Initial Value" section of the environment variables.

Operating the Database#

Apidog supports standard SQL queries, but does not support complex operations like stored procedures.

SELECT#

Run a query to fetch data from the database.
Example:
You can also use variables:
The query will return structured data as an array of objects — even if there's only one result:
[
    {
        "id": 1,
        "name": "jack"
    }
]
You can extract fields using JSONPath and save them as variables:
Variable name: user_id
JSONPath: $[0].id
To save the entire result set:
Variable name: userList
JSONPath: $
extract-results-to-variable.png

INSERT#

Insert new records into the database.
Example:
Dynamic data supported:

DELETE#

Delete records from the database.
Example:
Using a variable:

UPDATE#

Update existing records in the database.
Example:
Supports dynamic update:

Usage in Automated Test#

Database operations are supported during automated test, and SQL statements in test steps can use dynamic value expressions and variables.

Using Dynamic Value Expressions#

You can retrieve pre-step data using dynamic values in SQL statements:
01-apidog.gif

Using Variables#

Extract a variable (e.g., products_id) from previous test step:
extract-variable.png
Then reference them as {{variables}} in SQL for the next test steps:

Using ForEach Loop#

You can use ForEach loops in test steps to perform batch database operations.
Example 1: Query by Field in a Loop
Query by Field in a Loop.png
Note: 4 is the ID of the ForEach step — replace it with the correct ID in your workflow.
You can use dynamic values to fetch the expression:
02-apidog.gif
Example 2: Insert Multiple Fields in a Loop
This is especially helpful when you need to insert multiple records in batch or verify if certain data already exists in the database.

FAQs#

How to fix authentication errors when connecting to MySQL 8?
The latest MySQL module in Apidog does not fully support the caching_sha2_password, the default authentication method in MySQL 8.
To work around this, you need to specify the mysql_native_password mode to modify the MySQL password: Connect to MySQL using other tools and run the following SQL command:
Replace username and 123456 with your actual username and password.
Modified at 2025-06-25 07:57:16
Previous
Overview
Next
MongoDB
Built with