---
title: Install & configure NRDOT for MySQL monitoring with Ansible
source: https://docs.newrelic.com/docs/opentelemetry/db360/mysql/ansible
---

You can install and configure the NRDOT Collector for MySQL monitoring using the `newrelic.newrelic_install` Ansible role. The role installs the collector, creates the monitoring user, and configures the collector in a single play.

## Prerequisites [#prerequisites]

-   A New Relic account with a valid [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#overview-keys).
-   A New Relic [account ID](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/account-id).
-   MySQL 5.7 or later.
-   Ansible Core 2.13 or 2.14, Python 3.10, and the `ansible.windows` and `ansible.utils` collections.
-   A Linux collector host running Debian/Ubuntu or RHEL/CentOS.
-   For self-hosted MySQL: administrative access to your MySQL server (the `root` account or equivalent), using password-based authentication.
-   For MySQL or Aurora on AWS RDS: network connectivity from the collector host to the RDS endpoint, and the RDS master username and password.
-   Network connectivity to [New Relic OTLP endpoint](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp) for your region.

For detailed requirements, refer to [Compatibility and prerequisites](https://docs.newrelic.com/docs/opentelemetry/db360/mysql/compatibility).

## Install the role [#ansible-install-role]

```bash
ansible-galaxy install newrelic.newrelic_install
```

Make sure the required collections are also installed:

```bash
ansible-galaxy collection install ansible.windows ansible.utils
```

## Configure the playbook [#ansible-configure]

**Self-hosted MySQL**

This role monitors one or more MySQL instances from a single collector. Instead of a single host/port/credential set, it reads two files that must already exist on the target host: an instances file (YAML) listing every instance to monitor, and a secrets file (`KEY=VALUE`) with an admin login and password for each, indexed to match. See the [CLI install](https://docs.newrelic.com/docs/opentelemetry/db360/mysql/cli/#cli-install) page for the exact file formats.

Create a file named `playbook.yml` and copy the following content into it. Set `targets` to `mysql-otel` and replace the placeholder values with your own:

```yaml
- name: Install New Relic NRDOT for MySQL
  hosts: all
  roles:
    - role: newrelic.newrelic_install
  vars:
    targets:
      - mysql-otel
  environment:
    NEW_RELIC_API_KEY: <API key>
    NEW_RELIC_ACCOUNT_ID: <Account ID>
    NEW_RELIC_REGION: <Region>
    NR_CLI_MYSQL_CONFIG_PRESET: <1 Basic, 2 Advanced, default 1>
    NR_CLI_MYSQL_INSTANCES_FILE: <path to the instances YAML file on the target host>
    NR_CLI_MYSQL_SECRETS_FILE: <path to the secrets file (KEY=VALUE per instance) on the target host>
```

> #### ⚠️ IMPORTANT
>
> The role connects to MySQL over TCP using a password, so the admin account in your secrets file must use password-based authentication. On some Debian/Ubuntu installs, `root`@`localhost` defaults to the `auth_socket` plugin (no password, local-socket only), which won't work here. Switch it before running the playbook:
>
> ```bash
> mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<password>';"
> ```

> #### 💡 TIP
>
> To enable debug logging, add `verbosity: "debug"` under `vars` in the playbook.

| Variable                      | Description                                                                                                                       | Default |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `NR_CLI_MYSQL_CONFIG_PRESET`  | NRDOT configuration: 1 for Basic 2 for Advanced                                                                                   | `1`     |
| `NR_CLI_MYSQL_INSTANCES_FILE` | Required. Path to the instances YAML file, already present on the target host.                                                    | None    |
| `NR_CLI_MYSQL_SECRETS_FILE`   | Required. Path to the secrets file (`KEY=VALUE`, one admin login/password pair per instance), already present on the target host. | None    |

> #### 💡 TIP
>
> To monitor more than one MySQL instance from this collector, add more entries to the instances file and matching numbered credentials (`_2`, `_3`, ...) to the secrets file. An instance that fails its checks is skipped with a logged reason rather than aborting the whole install.

**MySQL or Aurora on AWS RDS**

This role monitors one or more RDS MySQL or Aurora endpoints from a single collector, using the same instances file / secrets file pattern as self-hosted (both files must already exist on the target host). Create a file named `playbook.yml` and copy the following content into it. Set `targets` to `mysql-otel-rds` and replace the placeholder values with your own:

```yaml
- name: Install New Relic NRDOT for MySQL on RDS
  hosts: all
  roles:
    - role: newrelic.newrelic_install
  vars:
    targets:
      - mysql-otel-rds
  environment:
    NEW_RELIC_API_KEY: <API key>
    NEW_RELIC_ACCOUNT_ID: <Account ID>
    NEW_RELIC_REGION: <Region>
    NR_CLI_MYSQL_CONFIG_PRESET: <1 Basic, 2 Advanced, default 1>
    NR_CLI_MYSQL_INSTANCES_FILE: <path to the instances YAML file on the target host, using RDS endpoints as host>
    NR_CLI_MYSQL_SECRETS_FILE: <path to the secrets file (KEY=VALUE per instance) on the target host>
```

> #### 💡 TIP
>
> To enable debug logging, add `verbosity: "debug"` under `vars` in the playbook.

| Variable                      | Description                                                                                                                               | Default |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `NR_CLI_MYSQL_CONFIG_PRESET`  | NRDOT configuration: 1 for Basic 2 for Advanced                                                                                           | `1`     |
| `NR_CLI_MYSQL_INSTANCES_FILE` | Required. Path to the instances YAML file, using RDS endpoints as `host`, already present on the target host.                             | None    |
| `NR_CLI_MYSQL_SECRETS_FILE`   | Required. Path to the secrets file (`KEY=VALUE`, one RDS master username/password pair per instance), already present on the target host. | None    |

> #### 💡 TIP
>
> To monitor more than one RDS MySQL or Aurora endpoint from this collector, add more entries to the instances file and matching numbered credentials to the secrets file. An instance that fails its checks is skipped with a logged reason rather than aborting the whole install.

## Run the playbook [#ansible-run]

```bash
ansible-playbook -i <inventory_file> <playbook_file>.yml
```

## Find and use your data [#find]

Once your data is being collected, you can access comprehensive MySQL database monitoring through the New Relic UI.

To find your MySQL database entity in New Relic:

1.  Go to **[one.newrelic.com](https://one.newrelic.com) > All capabilities > Databases**.
2.  From the **Entity type** dropdown, select **MySQL instance**, then click **Apply**.
3.  Select your MySQL database from the list of entities.

## Related documentation [#related]

[Introduction to MySQL monitoring with NRDOT](https://docs.newrelic.com/docs/opentelemetry/db360/mysql/introduction)

Learn about all the available installation methods for MySQL monitoring with New Relic.

[CLI install](https://docs.newrelic.com/docs/opentelemetry/db360/mysql/cli)

Learn how to install and configure MySQL monitoring with a single New Relic CLI command.

[Chef install](https://docs.newrelic.com/docs/opentelemetry/db360/mysql/chef)

Learn how to install and configure MySQL monitoring at scale with the newrelic-install Chef cookbook.

[Helm chart install](https://docs.newrelic.com/docs/opentelemetry/db360/mysql/helm)

Learn how to install and configure MySQL monitoring on Kubernetes with the mysql-otel Helm chart.
