> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spojit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL

> Execute queries, manage tables, and perform CRUD operations on MySQL databases.

The MySQL connector lets your workflows interact with any MySQL-compatible database, including Amazon RDS, Google Cloud SQL, PlanetScale, and self-hosted instances.

<Snippet file="connection-note.mdx" />

## Connection setup

<Steps>
  <Step title="Gather your MySQL credentials">
    You'll need the following:

    * **Host** (e.g., `localhost`, `db.example.com`, or an RDS endpoint)
    * **Port** (default: `3306`)
    * **Username** (e.g., `root` or a dedicated application user)
    * **Password**
    * **Database** (optional): the default database to connect to
  </Step>

  <Step title="Add the connection in Spojit">
    Go to **Connections** in Spojit, click **Add Connection**, select **MySQL**, and enter:

    * **Host**: Your MySQL server hostname or IP
    * **Port**: MySQL port number (default `3306`)
    * **Username**: Database username
    * **Password**: Database password
    * **Database** (optional): Default database name
    * **Use SSL** (optional): Enable for cloud-hosted databases
  </Step>
</Steps>

<Tip>
  **Cloud databases**: Most cloud providers require SSL connections. Enable the **Use SSL** toggle when connecting to AWS RDS, Google Cloud SQL, Azure Database for MySQL, or PlanetScale.
</Tip>

### Common MySQL settings

| Provider         | Host example                              | Port | Notes                                              |
| ---------------- | ----------------------------------------- | ---- | -------------------------------------------------- |
| AWS RDS          | `mydb.abc123.us-east-1.rds.amazonaws.com` | 3306 | Enable SSL, allow security group access            |
| Google Cloud SQL | `10.0.0.3` (private IP) or via proxy      | 3306 | Use Cloud SQL Auth Proxy for secure access         |
| PlanetScale      | `aws.connect.psdb.cloud`                  | 3306 | SSL required, use connection string from dashboard |
| Self-hosted      | `localhost` or server IP                  | 3306 | Ensure firewall allows connections                 |

## Tools

<AccordionGroup>
  <Accordion title="execute-query: Execute a raw SQL query">
    Execute any SQL statement including SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and more. Supports parameterized queries with `?` placeholders.

    <ParamField body="query" type="string" required>
      SQL query to execute.
    </ParamField>

    <ParamField body="params" type="unknown[]">
      Parameterized query values for `?` placeholders.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "query": "SELECT id, name, email FROM users WHERE status = ? LIMIT 10",
      "params": ["active"]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "data": {
        "rows": [
          { "id": 1, "name": "Alice", "email": "alice@example.com" },
          { "id": 2, "name": "Bob", "email": "bob@example.com" }
        ],
        "fields": [
          { "name": "id", "type": 3 },
          { "name": "name", "type": 253 },
          { "name": "email", "type": 253 }
        ]
      }
    }
    ```
  </Accordion>

  <Accordion title="list-databases: List all databases">
    List all databases accessible with the current credentials.

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "data": {
        "databases": ["information_schema", "myapp", "analytics"]
      }
    }
    ```
  </Accordion>

  <Accordion title="list-tables: List tables in a database">
    <ParamField body="database" type="string">
      Database name. Defaults to the connection's database.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "database": "myapp"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "data": {
        "tables": ["users", "orders", "products", "sessions"]
      }
    }
    ```
  </Accordion>

  <Accordion title="describe-table: Get table schema">
    Returns column definitions and the CREATE TABLE statement for a table.

    <ParamField body="table" type="string" required>
      Table name.
    </ParamField>

    <ParamField body="database" type="string">
      Database name. Defaults to the connection's database.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "table": "users"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "data": {
        "columns": [
          { "Field": "id", "Type": "int", "Null": "NO", "Key": "PRI", "Default": null, "Extra": "auto_increment" },
          { "Field": "name", "Type": "varchar(255)", "Null": "NO", "Key": "", "Default": null, "Extra": "" },
          { "Field": "email", "Type": "varchar(255)", "Null": "NO", "Key": "UNI", "Default": null, "Extra": "" }
        ],
        "createStatement": "CREATE TABLE `users` (\n  `id` int NOT NULL AUTO_INCREMENT,\n  `name` varchar(255) NOT NULL,\n  `email` varchar(255) NOT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `email` (`email`)\n) ENGINE=InnoDB"
      }
    }
    ```
  </Accordion>

  <Accordion title="insert-rows: Insert rows into a table">
    <ParamField body="table" type="string" required>
      Table name.
    </ParamField>

    <ParamField body="rows" type="object[]" required>
      Array of row objects to insert.
    </ParamField>

    <ParamField body="database" type="string">
      Database name. Defaults to the connection's database.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "table": "users",
      "rows": [
        { "name": "Alice", "email": "alice@example.com" },
        { "name": "Bob", "email": "bob@example.com" }
      ]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "data": {
        "affectedRows": 2,
        "insertId": 42
      }
    }
    ```
  </Accordion>

  <Accordion title="update-rows: Update rows matching a condition">
    <ParamField body="table" type="string" required>
      Table name.
    </ParamField>

    <ParamField body="set" type="object" required>
      Column values to update.
    </ParamField>

    <ParamField body="where" type="string" required>
      WHERE clause. Use `?` placeholders for parameterized values.
    </ParamField>

    <ParamField body="params" type="unknown[]">
      Values for `?` placeholders in the WHERE clause.
    </ParamField>

    <ParamField body="database" type="string">
      Database name. Defaults to the connection's database.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "table": "users",
      "set": { "status": "active" },
      "where": "last_login > ?",
      "params": ["2024-01-01"]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "data": {
        "affectedRows": 15
      }
    }
    ```
  </Accordion>

  <Accordion title="delete-rows: Delete rows matching a condition">
    <ParamField body="table" type="string" required>
      Table name.
    </ParamField>

    <ParamField body="where" type="string" required>
      WHERE clause. Use `?` placeholders for parameterized values.
    </ParamField>

    <ParamField body="params" type="unknown[]">
      Values for `?` placeholders in the WHERE clause.
    </ParamField>

    <ParamField body="database" type="string">
      Database name. Defaults to the connection's database.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "table": "sessions",
      "where": "expires_at < ?",
      "params": ["2024-01-01"]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "data": {
        "affectedRows": 128
      }
    }
    ```
  </Accordion>
</AccordionGroup>
