Grafana配置Mysql作为持久化数据库时,提示“ Access denied for user”

114 篇文章 0 订阅

1、问题

在部署Grafana时,想使用自建的Mysql作为持久化数据库而不是默认的sqlite3数据库。

2、版本信息

系统:Centos7.9
Grafana:grafana-enterprise-9.1.7-1.x86_64.rpm
Mysql:mysql-5.7.19-1.el7.x86_64.rpm
均部署在同一台机器上。
注意:均部署在同一台机器上!

3、处理过程

按照在grafana.ini中给出的例子配置后,发现启动会报错
“level=error msg="alert migration failure: could not get migration log" error="failed to check table existence: Error 1045: Access denied for user 'xxxx'@'::1' (using password: YES)".

配置文件中的说明:

#################################### Database ####################################
[database]
# You can configure the database connection by specifying type, host, name, user and password
# as separate properties or as on string using the url properties.

# Either "mysql", "postgres" or "sqlite3", it's your choice
;type = sqlite3
;host = 127.0.0.1:3306
;name = grafana
;user = root
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
;password =
# Use either URL or the previous fields to configure the database
# Example: mysql://user:secret@host:port/database
;url =
# For "postgres" only, either "disable", "require" or "verify-full"
;ssl_mode = disable

# Database drivers may support different transaction isolation levels.
# Currently, only "mysql" driver supports isolation levels.
# If the value is empty - driver's default isolation level is applied.
# For "mysql" use "READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ" or "SERIALIZABLE".
;isolation_level =

;ca_cert_path =
;client_key_path =
;client_cert_path =
;server_cert_name =

# For "sqlite3" only, path relative to data_path setting
;path = grafana.db

按照例子配置了type、host、name、user、password后,启动报错如下:

sudo systemctl start grafana-server
Job for grafana-server.service failed because the control process exited with error code. See "systemctl status grafana-server.service" and "journalctl -xe" for details.

于是开始各种尝试,修改密码、修改数据库端口、使用URL连接等等等等,网上也搜了好多,都没有解决。。。

直到突然发现官网上对 host 有一句提示。

官网原文地址:https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#host

[database]
Grafana needs a database to store users and dashboards (and other things). By default it is configured to use sqlite3 which is an embedded database (included in the main Grafana binary).

type
Either mysql, postgres or sqlite3, it’s your choice.

host
Only applicable to MySQL or Postgres. Includes IP or hostname and port or in case of Unix sockets the path to it. For example, for MySQL running on the same host as Grafana: host = 127.0.0.1:3306 or with Unix sockets: host = /var/run/mysqld/mysqld.sock

name
The name of the Grafana database. Leave it set to grafana or some other name.

user
The database user (not applicable for sqlite3).

password
The database user’s password (not applicable for sqlite3). If the password contains # or ; you have to wrap it with triple quotes. For example """#password;"""

url
Use either URL or the other fields below to configure the database Example: mysql://user:secret@host:port/database

对,没错,使用 host = /var/run/mysqld/mysqld.sock 进行连接(这里根据实际情况进行配置mysqld.sock的路径)成功启动了…

只想吐槽一句,这个不能在说明里详述一下吗(T-T)…

对了,使用mysqld.sock去做配置需要Grafana和Mysql配置在同一台机器上。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值