---
title: "MySQL"
date: 0001-01-01
summary: "MySQL Connector #  Register MySQL Connector #  curl -XPOST &#34;http://localhost:9000/connector/&#34; -d &#39;{ &#34;name&#34;: &#34;MySQL Connector&#34;, &#34;description&#34;: &#34;Fetch data from MySQL database.&#34;, &#34;category&#34;: &#34;database&#34;, &#34;icon&#34;: &#34;/assets/icons/connector/mysql/icon.png&#34;, &#34;tags&#34;: [ &#34;sql&#34;, &#34;storage&#34;, &#34;web&#34; ], &#34;url&#34;: &#34;http://coco.rs/connectors/mysql&#34;, &#34;assets&#34;: { &#34;icons&#34;: { &#34;default&#34;: &#34;/assets/icons/connector/mysql/icon.png&#34; } }, &#34;processor&#34;: { &#34;enabled&#34;: true, &#34;name&#34;: &#34;mysql&#34; } }&#39; Use the MySQL Connector #  The MySQL Connector allows you to index data from your database by executing a custom SQL query."
---

# MySQL Connector

## Register MySQL Connector

```shell
curl -XPOST "http://localhost:9000/connector/" -d '{
  "name": "MySQL Connector",
  "description": "Fetch data from MySQL database.",
  "category": "database",
  "icon": "/assets/icons/connector/mysql/icon.png",
  "tags": [
    "sql",
    "storage",
    "web"
  ],
  "url": "http://coco.rs/connectors/mysql",
  "assets": {
    "icons": {
      "default": "/assets/icons/connector/mysql/icon.png"
    }
  },
  "processor": {
    "enabled": true,
    "name": "mysql"
  }
}'
```


## Use the MySQL Connector

The MySQL Connector allows you to index data from your database by executing a custom SQL query.

### Configure MySQL Datasource

To configure your MySQL connection, you'll need to provide the connection details and the query to fetch the data.

`Connection URI`: The full MySQL connection string, including user, password, host, port, and database name.

`SQL Query`: The SQL query that will be executed to fetch the data for indexing. You can use `JOIN`s and select specific columns.

`Last Modified Field`: (Optional) For incremental sync, specify a timestamp or datetime column (e.g., `updated_at`). The connector will only fetch rows where this field's value is newer than the last sync time.

`Enable Pagination`: (Optional) A boolean (`true` or `false`) to enable paginated fetching. This is highly recommended for large tables to avoid high memory usage.

`Page Size`: (Optional) The number of records to fetch per page when pagination is enabled. Defaults to `500`.

`Field Mapping`: (Optional) An advanced feature to map columns from your SQL query to specific document fields like `id`, `title`, `content`, and custom metadata.

### Datasource Configuration

Each datasource has its own sync configuration and MySQL settings:

```shell
curl -H 'Content-Type: application/json' -XPOST "http://localhost:9000/datasource/" -d '{
    "name": "My MySQL Documents",
    "type": "connector",
    "enabled": true,
    "connector": {
        "id": "mysql",
        "config": {
            "connection_uri": "user:password@tcp(localhost:3306)/database",
            "sql": "SELECT * from DOC",
            "pagination": true,
            "page_size": 500,
            "last_modified_field": "updated",
            "field_mapping": {
                "enabled": true,
                "mapping": {
                    "hashed": true,
                    "id": "id",
                    "title": "title",
                    "url": "url",
                    "metadata": [
                        {
                            "name": "version",
                            "value": "v"
                        }
                    ]
                }
            }
        }
    },
    "sync": {
        "enabled": true,
        "interval": "30s"
    }
}'
```

## Supported Config Parameters for MySQL Connector

Below are the configuration parameters supported by the MySQL Connector:

### Datasource Config Parameters

| **Field**              | **Type**   | **Description**                                                                                |
|------------------------|------------|------------------------------------------------------------------------------------------------|
| `connection_uri`       | `string`   | The full MySQL connection URI (e.g., user:password@tcp(localhost:3306)/database) (required).  |
| `sql`                  | `string`   | The SQL query to execute for fetching data (required).                                        |
| `last_modified_field`  | `string`   | Optional. The name of a timestamp/datetime column used for incremental synchronization.        |
| `pagination`           | `boolean`  | Optional. Set to true to enable pagination for large queries. Defaults to false.               |
| `page_size`            | `integer`  | Optional. The number of records to fetch per page when pagination is enabled. Defaults to 500. |
| `field_mapping`        | `object`   | Optional. Provides advanced control to map query columns to standard document fields.          |
| `sync.enabled`         | `boolean`  | Enable/disable syncing for this datasource.                                                    |
| `sync.interval`        | `string`   | Sync interval for this datasource (e.g., "30s", "5m", "1h").                                   |

