> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/m/mysql-adapter.md).

# MySQL Adapter

MySQL Adapter can hold asset data in a view or table. OctoXLabs runs a query against your MySQL database and adds each row to the device inventory.

## Use cases

* List the devices read from your MySQL view.

```
Adapters = mysql-db-adapter
```

## Before you begin

### Network

| Source              | Destination | Port                          | Protocol |
| ------------------- | ----------- | ----------------------------- | -------- |
| OctoXLabs connector | MySQL host  | 3306 (or the configured port) | TCP      |

### Required permissions

| Scope or role | Permission | Needed for                                    |
| ------------- | ---------- | --------------------------------------------- |
| SELECT        | Read       | The database and the view or tables you query |

## Create credentials in MySQL Adapter

{% stepper %}
{% step %}

### Open the privileges screen

In your MySQL management tool, go to Management > Users and Privileges and select the user to grant permissions to.
{% endstep %}

{% step %}

### Add the schema

Select Schema Privileges, then Add Entry. Select the database and select OK.
{% endstep %}

{% step %}

### Grant SELECT

Check SELECT under Object Rights and select Apply.
{% endstep %}

{% step %}

### Sign in once

Log in to the database with this user once to avoid an error.
{% endstep %}
{% endstepper %}

## Connection parameters

| Parameter                       | Required    | Type    | Default  | Description                                                                                         |
| ------------------------------- | ----------- | ------- | -------- | --------------------------------------------------------------------------------------------------- |
| IP (`ip`)                       | Yes         | String  |          | IP address or hostname of the MySQL host.                                                           |
| Port (`port`)                   | No          | Integer | 3306     | MySQL port.                                                                                         |
| Domain (`domain`)               | No          | String  |          | When set, the login is sent as `DOMAIN\username`.                                                   |
| Database (`database`)           | Yes         | String  |          | Database to connect to.                                                                             |
| Username (`username`)           | Yes         | String  |          | Account used to connect.                                                                            |
| Password (`password`)           | Yes         | String  |          | Password of the account.                                                                            |
| Query Timeout (`query_timeout`) | No          | Integer | 60       | Read timeout in seconds.                                                                            |
| View Name (`view_name`)         | Conditional | String  |          | View to query. Required unless you set a custom query.                                              |
| Primary Field (`primary_field`) | No          | String  | Hostname | Column of the view used as the device host name. It is returned as `Hostname`.                      |
| Custom Query (`custom_query`)   | No          | SQL     |          | Custom SQL. Must be a single read-only SELECT or WITH statement. It takes precedence over the view. |

## Troubleshooting

| Error message                                        | Cause                                          | Fix                                  |
| ---------------------------------------------------- | ---------------------------------------------- | ------------------------------------ |
| It is mandatory to enter either custom query or view | Neither a view name nor a custom query is set. | Enter a view name or a custom query. |

## Change history

{% hint style="info" %}
Available starting from version 5.0.0.
{% endhint %}
