> [!CAUTION]
> **Caution:** As of September 28, 2026, the legacy Monitoring agent has reached its end of support. Standard maintenance and bug fixes are no longer provided. We strongly recommend migrating to one of the [supported alternatives](https://docs.cloud.google.com/monitoring/agent.md.txt). For more information about this deprecation, see [Legacy
> Monitoring and Logging agents end of support](https://docs.cloud.google.com/stackdriver/docs/deprecations/legacy-agents).

MySQL is a relational database management system that runs as a server
providing multi-user access to a number of databases.
For more information visit [mysql.com](http://www.mysql.com/).

This functionality is only available for agents running on Linux. It is
not available on Windows.

> [!NOTE]
> **Note:** You can now collect metrics from your MySQL instance using the [Ops Agent](https://docs.cloud.google.com/stackdriver/docs/solutions/agents/ops-agent.md.txt), the primary and preferred agent for collecting telemetry from your Compute Engine instances. For details, see [configuring the Ops Agent for
> MySQL](https://docs.cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/third-party/mysql).

## Discovery

Even if the MySQL plugin is not configured, Monitoring will
discover MySQL services running in your Cloud Platform project by:

- Searching instance names for **mysql**
- Checking for ports opened to **3306** via firewall rules

To see the metrics for MySQL, do the following:

1. In the Google Cloud console, go to the **Dashboards** page:

   [Go to **Dashboards**](https://console.cloud.google.com/monitoring/dashboards)

   <br />

   If you use the search bar to find this page, then select the result whose subheading is
   **Monitoring**.
2. Select the **MySQL** dashboard from the list.

## Configuring MySQL monitoring

The Monitoring agent uses the
[Connector/C API](http://dev.mysql.com/doc/c-api/8.0/en/)
to monitor MySQL. For Linux distributions that don't include the Connector/C
library with MySQL, run the appropriate command to install it:

### Ubuntu 16.04 LTS and Ubuntu 18.04 LTS

```mysql
    sudo apt-get install libmysqlclient20
```

### Ubuntu 19.10

```mysql
    sudo apt-get install libmysqlclient21
```

### Debian 9

```mysql
    sudo apt-get install libmariadbclient18
```

### Amazon AMI 2016.03 or later

```mysql
    sudo yum install mysql-libs
```

### SLES 12

```mysql
    sudo zypper install libmysqlclient18
```

### SLES 15

```mysql
    sudo zypper install libmariadb3
```

## Configuring Monitoring to monitor MySQL

After you [install the monitoring agent](https://docs.cloud.google.com/monitoring/agent/monitoring/installation.md.txt), use
the following instructions to configure the MySQL plugin on your instances.

### Prerequisites

For MySQL collection, you must add a user with a password to MySQL that can run
the **SHOW STATUS** command. This user and password are referred to as
`STATS_USER` and `STATS_PASS` in the following config file.

### Enabling the MySQL monitoring plugin

MySQL is configured per database on your system. At the moment, no drop-in
configuration is available. The following configuration file shows how to
configure one database, named `DATABASE_NAME`.
You would need to use that configuration as a template for your databases.

On your VM instance, download [mysql.conf](https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/mysql.conf)
from the [GitHub configuration repository](https://github.com/Stackdriver/stackdriver-agent-service-configs)
and place it in the directory `/etc/stackdriver/collectd.d/`:

```mysql
(cd /etc/stackdriver/collectd.d/ && sudo curl -O https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/mysql.conf)
```

As **root** , edit the downloaded configuration file and add information about
your databases. Inline comments point out where you need to add configuration
for additional databases. Wherever you see `DATABASE_NAME`, substitute the name
of your database.

After editing the configuration file, restart the monitoring agent by running the following command:

```mysql
sudo service stackdriver-agent restart
```

For more information on the `collectd` `mysql` plugin, see
[Plugin:MySQL](https://collectd.org/wiki/index.php/Plugin:MySQL).

## What is monitored

The full list of metrics the MySQL plugin monitors is at
[Agent metrics: mysql](https://docs.cloud.google.com/monitoring/api/metrics_agent.md.txt#agent-mysql).