{"id":704,"date":"2023-05-16T11:51:44","date_gmt":"2023-05-16T03:51:44","guid":{"rendered":"https:\/\/play.datalude.com\/blog\/?p=704"},"modified":"2023-05-16T11:51:46","modified_gmt":"2023-05-16T03:51:46","slug":"telegraf-mysql-monitor-refuses-to-connect","status":"publish","type":"post","link":"https:\/\/play.datalude.com\/blog\/2023\/05\/telegraf-mysql-monitor-refuses-to-connect\/","title":{"rendered":"Telegraf mysql monitor refuses to connect"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I'd set up a grafana server to collect some metrics from a few servers, and as part of that I wanted to get some Mysql data from a couple of them. Easy right? So on the first server I logged into mysql and set up a user for this:<br><\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'telegraf-client'@'localhost' IDENTIFIED BY 'xxxxxxx';\nGRANT REPLICATION CLIENT ON *.* TO 'telegraf-client'@'localhost' WITH MAX_USER_CONNECTIONS 5;\nGRANT PROCESS ON *.* TO 'telegraf-client'@'localhost';\nGRANT SELECT ON performance_schema.* TO 'telegraf-client'@'localhost';\nFLUSH PRIVILEGES;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And the in \/etc\/telegraf\/telegraf.conf I added:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;&#91;inputs.mysql]]\n  servers = &#91;\"telegraf-client:xxxxxxxxxxx@tcp(127.0.0.1:3306)\/\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All good. Restart telegraf with systemctl and off we go: data flowed into grafana in a veritable torrent. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the second server, I did EXACTLY THE SAME THING, but all I could see in the mysql error log was [Warning] Access denied for user ' telegraf-client'@'127.0.0.1' (using password: YES)<br><br>I tried everything I could think of over several days. I tried localhost instead of the IP. I tried different quotes, I tried spaces in the brackets, I tried specifying information_schema database. I trawled forums. I tried deleting the user and recreating it as something else (maybe it didn't like the hyphen? getting desperate here). Nope. <br>I tried using the root user and deb-sys-maint. Nope. From the command line it would connect with 'localhost' but not 127.0.0.1. I checked the hosts file, the mysql config. Many many hours wasted. <br><br>Here is what worked. I have no idea why. The servers and setups were identical. This is the answer to one of the Mysteries of Linux: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>servers = &#91;\"telegraf-client:xxxxxxxxxx@unix(\/var\/run\/mysqld\/mysqld.sock)\/\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">May it save you many hours. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I'd set up a grafana server to collect some metrics from a few servers, and as part of that I wanted to get some Mysql data from a couple of them. Easy right? So on the first server I logged into mysql and set up a user for this:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1,4],"tags":[134],"class_list":["post-704","post","type-post","status-publish","format-standard","hentry","category-it","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/comments?post=704"}],"version-history":[{"count":0,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/704\/revisions"}],"wp:attachment":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/media?parent=704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/categories?post=704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/tags?post=704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}