[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[],[],null,["# MySQL plugin\n\nMySQL is a relational database management system that runs as a server\nproviding multi-user access to a number of databases.\nFor more information visit [mysql.com](http://www.mysql.com/).\n\nThis functionality is only available for agents running on Linux. It is\nnot available on Windows.\n| **Note:** You can now collect metrics from your MySQL instance using the [Ops Agent](/stackdriver/docs/solutions/agents/ops-agent), the primary and preferred agent for collecting telemetry from your Compute Engine instances. For details, see [configuring the Ops Agent for\n| MySQL](/stackdriver/docs/solutions/agents/ops-agent/third-party/mysql).\n\nDiscovery\n---------\n\nEven if the MySQL plugin is not configured, Monitoring will\ndiscover MySQL services running in your Cloud Platform project by:\n\n- Searching instance names for **mysql**\n- Checking for ports opened to **3306** via firewall rules\n\nTo see the metrics for MySQL, do the following:\n\n1. In the Google Cloud console, go to the **Dashboards** page:\n\n [Go to **Dashboards**](https://console.cloud.google.com/monitoring/dashboards)\n\n \u003cbr /\u003e\n\n If you use the search bar to find this page, then select the result whose subheading is\n **Monitoring**.\n2. Select the **MySQL** dashboard from the list.\n\nConfiguring MySQL monitoring\n----------------------------\n\nThe Monitoring agent uses the\n[Connector/C API](http://dev.mysql.com/doc/c-api/8.0/en/)\nto monitor MySQL. For Linux distributions that don't include the Connector/C\nlibrary with MySQL, run the appropriate command to install it: \n\n### Ubuntu 16.04 LTS and Ubuntu 18.04 LTS\n\n sudo apt-get install libmysqlclient20\n\n### Ubuntu 19.10\n\n sudo apt-get install libmysqlclient21\n\n### Debian 9\n\n sudo apt-get install libmariadbclient18\n\n### Amazon AMI 2016.03 or later\n\n sudo yum install mysql-libs\n\n### SLES 12\n\n sudo zypper install libmysqlclient18\n\n### SLES 15\n\n sudo zypper install libmariadb3\n\nConfiguring Monitoring to monitor MySQL\n---------------------------------------\n\nAfter you [install the monitoring agent](/monitoring/agent/monitoring/installation), use\nthe following instructions to configure the MySQL plugin on your instances.\n\n### Prerequisites\n\nFor MySQL collection, you must add a user with a password to MySQL that can run\nthe **SHOW STATUS** command. This user and password are referred to as\n`STATS_USER` and `STATS_PASS` in the following config file.\n\n### Enabling the MySQL monitoring plugin\n\nMySQL is configured per database on your system. At the moment, no drop-in\nconfiguration is available. The following configuration file shows how to\nconfigure one database, named `DATABASE_NAME`.\nYou would need to use that configuration as a template for your databases.\n\nOn your VM instance, download [mysql.conf](https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/mysql.conf)\nfrom the [GitHub configuration repository](https://github.com/Stackdriver/stackdriver-agent-service-configs)\nand place it in the directory `/etc/stackdriver/collectd.d/`: \n\n (cd /etc/stackdriver/collectd.d/ && sudo curl -O https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/mysql.conf)\n\nAs **root** , edit the downloaded configuration file and add information about\nyour databases. Inline comments point out where you need to add configuration\nfor additional databases. Wherever you see `DATABASE_NAME`, substitute the name\nof your database.\n\nAfter editing the configuration file, restart the monitoring agent by running the following command: \n\n sudo service stackdriver-agent restart\n\nFor more information on the `collectd` `mysql` plugin, see\n[Plugin:MySQL](https://collectd.org/wiki/index.php/Plugin:MySQL).\n\nWhat is monitored\n-----------------\n\nThe full list of metrics the MySQL plugin monitors is at\n[Agent metrics: mysql](/monitoring/api/metrics_agent#agent-mysql)."]]