Reset lost admin password of Grafana server (CentOS 7)

It could happen to lose your Grafana admin password and luckily there is a pretty easy way for the system administrator of the Grafana server to reset the admin password.
There is really good and simple page of how you can reset the admin password with grafana-cli in the documentation of Grafana website. Probably you can check it, too.

The problem is that most distributions like the one we use (CentOS 7) rearrange the home directory of the Grafana software and if you try to use grafana-cli you’ll end up with the error mentioned in the section below the solution we offer you here! And you really could mess it up and hurry to say this software is buggy!
First, “grafana-cli admin reset-admin-password ” needs to know where is your configuration file and Grafana home directory, because from the configuration it will extract what kind of back-end server you use like sqlite3 or MySQL (or other) and the path or login data if needed to the back-end, then it will reset the password with the given one. At the bottom of this article, there is another method of resetting the Grafana admin password without grafana-cli – manual reset in the database.
So first you should check with what command-line arguments was your instance of Grafana server started:

[root@monitoring ~]# ps axuf|grep grafana
grafana    490  0.0  0.0 1274696 30344 ?       Ssl  14:18   0:09 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins cfg:default.paths.provisioning=/etc/grafana/provisioning

It appeared that Grafana server in CentOS 7 has the config in “/etc/grafana/grafana.ini”, plugins and sessions are in “/var/lib/grafana”, logs in “/var/log/” and the home directory as of grafana-cli expect to be is in “/usr/share/grafana” (look below to see why you cannot use this directory for proper resetting of the admin password). So you should pass 2 additional arguments to be sure “grafana-cli admin” will reset the admin password in the right place:

[root@monitoring ~]# grafana-cli admin reset-admin-password --homepath "/usr/share/grafana" --config "/etc/grafana/grafana.ini" admin
INFO[09-30|22:45:29] Connecting to DB                         logger=sqlstore dbtype=sqlite3
INFO[09-30|22:45:29] Starting DB migration                    logger=migrator

Admin password changed successfully ✔

[root@monitoring ~]#

So you MUST see just 2-3 lines above, nothing more! Just output saying the tool connection to the database and then successful reset.
This is the most common pitfall different Linux distros just change the directory scheme of the configuration and data files of the software and you might have real problems when you try to run it with the default values (those set by the developer)!

Several typical errors got in attempt to reset the Grafana admin password

Using grafana-cli with the default values for all configuration and data files:

[root@monitoring ~]# grafana-cli admin reset-admin-password admin
Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath

OR you can try with just a home directory:

[root@monitoring ~]# grafana-cli admin reset-admin-password --homepath "/var/lib/grafana" admin
Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath
[root@monitoring ~]# ls -altr /var/lib/grafana
total 464
drwxr-xr-x.  3 grafana grafana   4096  9 Jun  2016 plugins
drwxr-xr-x. 18 grafana grafana   4096 31 Mar  2017 sessions
drwxr-xr-x. 26 root    root      4096 11 Apr  4,59 ..
drwxr-xr-x.  4 grafana grafana   4096 30 Sep 22,05 .

Or even you could try the home path in the link above “–homepath “/usr/share/grafana” and at first you might think it was a successful reset but it wasn’t, you just created a new grafana.db file and you should not do this! Of course, you still cannot log in, because the password is invalid! If you see the output below you DID not reset your password for sure!

[root@monitoring ~]# grafana-cli admin reset-admin-password --homepath "/usr/share/grafana" newpass
INFO[09-30|14:13:34] Connecting to DB                         logger=sqlstore dbtype=sqlite3
INFO[09-30|14:13:34] Starting DB migration                    logger=migrator
INFO[09-30|14:13:34] Executing migration                      logger=migrator id="create migration_log table"
INFO[09-30|14:13:34] Executing migration                      logger=migrator id="create user table"
INFO[09-30|14:13:34] Executing migration                      logger=migrator id="add unique index user.login"
INFO[09-30|14:13:34] Executing migration                      logger=migrator id="add unique index user.email"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="drop index UQE_user_login - v1"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="drop index UQE_user_email - v1"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="Rename table user to user_v1 - v1"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="create user table v2"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="create index UQE_user_login - v2"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="create index UQE_user_email - v2"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="copy data_source v1 to v2"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="Drop old table user_v1"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="Add column help_flags1 to user table"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="Update user table charset"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="Add last_seen_at column to user"
INFO[09-30|14:13:35] Executing migration                      logger=migrator id="Add missing user data"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="create temp user table v1-7"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="create index IDX_temp_user_email - v1-7"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="create index IDX_temp_user_org_id - v1-7"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="create index IDX_temp_user_code - v1-7"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="create index IDX_temp_user_status - v1-7"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="Update temp_user table charset"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="create star table"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="add unique index star.user_id_dashboard_id"
INFO[09-30|14:13:36] Executing migration                      logger=migrator id="create org table v1"
INFO[09-30|14:13:37] Executing migration                      logger=migrator id="create index UQE_org_name - v1"
INFO[09-30|14:13:37] Executing migration                      logger=migrator id="create org_user table v1"
INFO[09-30|14:13:37] Executing migration                      logger=migrator id="create index IDX_org_user_org_id - v1"
INFO[09-30|14:13:37] Executing migration                      logger=migrator id="create index UQE_org_user_org_id_user_id - v1"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="Update org table charset"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="Update org_user table charset"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="Migrate all Read Only Viewers to Viewers"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="create dashboard table"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="add index dashboard.account_id"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="add unique index dashboard_account_id_slug"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="create dashboard_tag table"
INFO[09-30|14:13:38] Executing migration                      logger=migrator id="add unique index dashboard_tag.dasboard_id_term"
INFO[09-30|14:13:39] Executing migration                      logger=migrator id="drop index UQE_dashboard_tag_dashboard_id_term - v1"
INFO[09-30|14:13:39] Executing migration                      logger=migrator id="Rename table dashboard to dashboard_v1 - v1"
INFO[09-30|14:13:39] Executing migration                      logger=migrator id="create dashboard v2"
INFO[09-30|14:13:39] Executing migration                      logger=migrator id="create index IDX_dashboard_org_id - v2"
INFO[09-30|14:13:39] Executing migration                      logger=migrator id="create index UQE_dashboard_org_id_slug - v2"
INFO[09-30|14:13:39] Executing migration                      logger=migrator id="copy dashboard v1 to v2"
INFO[09-30|14:13:39] Executing migration                      logger=migrator id="drop table dashboard_v1"
INFO[09-30|14:13:40] Executing migration                      logger=migrator id="alter dashboard.data to mediumtext v1"
INFO[09-30|14:13:40] Executing migration                      logger=migrator id="Add column updated_by in dashboard - v2"
INFO[09-30|14:13:40] Executing migration                      logger=migrator id="Add column created_by in dashboard - v2"
INFO[09-30|14:13:40] Executing migration                      logger=migrator id="Add column gnetId in dashboard"
INFO[09-30|14:13:40] Executing migration                      logger=migrator id="Add index for gnetId in dashboard"
INFO[09-30|14:13:40] Executing migration                      logger=migrator id="Add column plugin_id in dashboard"
INFO[09-30|14:13:40] Executing migration                      logger=migrator id="Add index for plugin_id in dashboard"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Add index for dashboard_id in dashboard_tag"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Update dashboard table charset"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Update dashboard_tag table charset"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Add column folder_id in dashboard"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Add column isFolder in dashboard"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Add column has_acl in dashboard"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Add column uid in dashboard"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Update uid column values in dashboard"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Add unique index dashboard_org_id_uid"
INFO[09-30|14:13:41] Executing migration                      logger=migrator id="Remove unique index org_id_slug"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="Update dashboard title length"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="Add unique index for dashboard_org_id_title_folder_id"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="create dashboard_provisioning"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="Rename table dashboard_provisioning to dashboard_provisioning_tmp_qwerty - v1"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="create dashboard_provisioning v2"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="create index IDX_dashboard_provisioning_dashboard_id - v2"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="create index IDX_dashboard_provisioning_dashboard_id_name - v2"
INFO[09-30|14:13:42] Executing migration                      logger=migrator id="copy dashboard_provisioning v1 to v2"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="drop dashboard_provisioning_tmp_qwerty"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="Add check_sum column"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="create data_source table"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="add index data_source.account_id"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="add unique index data_source.account_id_name"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="drop index IDX_data_source_account_id - v1"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="drop index UQE_data_source_account_id_name - v1"
INFO[09-30|14:13:43] Executing migration                      logger=migrator id="Rename table data_source to data_source_v1 - v1"
INFO[09-30|14:13:44] Executing migration                      logger=migrator id="create data_source table v2"
INFO[09-30|14:13:44] Executing migration                      logger=migrator id="create index IDX_data_source_org_id - v2"
INFO[09-30|14:13:44] Executing migration                      logger=migrator id="create index UQE_data_source_org_id_name - v2"
INFO[09-30|14:13:44] Executing migration                      logger=migrator id="copy data_source v1 to v2"
INFO[09-30|14:13:44] Executing migration                      logger=migrator id="Drop old table data_source_v1 #2"
INFO[09-30|14:13:44] Executing migration                      logger=migrator id="Add column with_credentials"
INFO[09-30|14:13:45] Executing migration                      logger=migrator id="Add secure json data column"
INFO[09-30|14:13:45] Executing migration                      logger=migrator id="Update data_source table charset"
INFO[09-30|14:13:45] Executing migration                      logger=migrator id="Update initial version to 1"
INFO[09-30|14:13:45] Executing migration                      logger=migrator id="Add read_only data column"
INFO[09-30|14:13:45] Executing migration                      logger=migrator id="create api_key table"
INFO[09-30|14:13:45] Executing migration                      logger=migrator id="add index api_key.account_id"
INFO[09-30|14:13:45] Executing migration                      logger=migrator id="add index api_key.key"
INFO[09-30|14:13:46] Executing migration                      logger=migrator id="add index api_key.account_id_name"
INFO[09-30|14:13:46] Executing migration                      logger=migrator id="drop index IDX_api_key_account_id - v1"
INFO[09-30|14:13:46] Executing migration                      logger=migrator id="drop index UQE_api_key_key - v1"
INFO[09-30|14:13:46] Executing migration                      logger=migrator id="drop index UQE_api_key_account_id_name - v1"
INFO[09-30|14:13:46] Executing migration                      logger=migrator id="Rename table api_key to api_key_v1 - v1"
INFO[09-30|14:13:46] Executing migration                      logger=migrator id="create api_key table v2"
INFO[09-30|14:13:46] Executing migration                      logger=migrator id="create index IDX_api_key_org_id - v2"
INFO[09-30|14:13:47] Executing migration                      logger=migrator id="create index UQE_api_key_key - v2"
INFO[09-30|14:13:47] Executing migration                      logger=migrator id="create index UQE_api_key_org_id_name - v2"
INFO[09-30|14:13:47] Executing migration                      logger=migrator id="copy api_key v1 to v2"
INFO[09-30|14:13:47] Executing migration                      logger=migrator id="Drop old table api_key_v1"
INFO[09-30|14:13:47] Executing migration                      logger=migrator id="Update api_key table charset"
INFO[09-30|14:13:47] Executing migration                      logger=migrator id="create dashboard_snapshot table v4"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="drop table dashboard_snapshot_v4 #1"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="create dashboard_snapshot table v5 #2"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="create index UQE_dashboard_snapshot_key - v5"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="create index UQE_dashboard_snapshot_delete_key - v5"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="create index IDX_dashboard_snapshot_user_id - v5"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="alter dashboard_snapshot to mediumtext v2"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="Update dashboard_snapshot table charset"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="create quota table v1"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="create index UQE_quota_org_id_user_id_target - v1"
INFO[09-30|14:13:48] Executing migration                      logger=migrator id="Update quota table charset"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="create plugin_setting table"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="create index UQE_plugin_setting_org_id_plugin_id - v1"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="Add column plugin_version to plugin_settings"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="Update plugin_setting table charset"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="create session table"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="Drop old table playlist table"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="Drop old table playlist_item table"
INFO[09-30|14:13:49] Executing migration                      logger=migrator id="create playlist table v2"
INFO[09-30|14:13:50] Executing migration                      logger=migrator id="create playlist item table v2"
INFO[09-30|14:13:50] Executing migration                      logger=migrator id="Update playlist table charset"
INFO[09-30|14:13:50] Executing migration                      logger=migrator id="Update playlist_item table charset"
INFO[09-30|14:13:50] Executing migration                      logger=migrator id="drop preferences table v2"
INFO[09-30|14:13:51] Executing migration                      logger=migrator id="drop preferences table v3"
INFO[09-30|14:13:51] Executing migration                      logger=migrator id="create preferences table v3"
INFO[09-30|14:13:51] Executing migration                      logger=migrator id="Update preferences table charset"
INFO[09-30|14:13:51] Executing migration                      logger=migrator id="create alert table v1"
INFO[09-30|14:13:51] Executing migration                      logger=migrator id="add index alert org_id & id "
INFO[09-30|14:13:51] Executing migration                      logger=migrator id="add index alert state"
INFO[09-30|14:13:51] Executing migration                      logger=migrator id="add index alert dashboard_id"
INFO[09-30|14:13:52] Executing migration                      logger=migrator id="create alert_notification table v1"
INFO[09-30|14:13:52] Executing migration                      logger=migrator id="Add column is_default"
INFO[09-30|14:13:52] Executing migration                      logger=migrator id="add index alert_notification org_id & name"
INFO[09-30|14:13:53] Executing migration                      logger=migrator id="Update alert table charset"
INFO[09-30|14:13:53] Executing migration                      logger=migrator id="Update alert_notification table charset"
INFO[09-30|14:13:53] Executing migration                      logger=migrator id="Drop old annotation table v4"
INFO[09-30|14:13:53] Executing migration                      logger=migrator id="create annotation table v5"
INFO[09-30|14:13:53] Executing migration                      logger=migrator id="add index annotation 0 v3"
INFO[09-30|14:13:53] Executing migration                      logger=migrator id="add index annotation 1 v3"
INFO[09-30|14:13:53] Executing migration                      logger=migrator id="add index annotation 2 v3"
INFO[09-30|14:13:54] Executing migration                      logger=migrator id="add index annotation 3 v3"
INFO[09-30|14:13:54] Executing migration                      logger=migrator id="add index annotation 4 v3"
INFO[09-30|14:13:54] Executing migration                      logger=migrator id="Update annotation table charset"
INFO[09-30|14:13:54] Executing migration                      logger=migrator id="Add column region_id to annotation table"
INFO[09-30|14:13:54] Executing migration                      logger=migrator id="Drop category_id index"
INFO[09-30|14:13:54] Executing migration                      logger=migrator id="Add column tags to annotation table"
INFO[09-30|14:13:55] Executing migration                      logger=migrator id="Create annotation_tag table v2"
INFO[09-30|14:13:55] Executing migration                      logger=migrator id="Add unique index annotation_tag.annotation_id_tag_id"
INFO[09-30|14:13:55] Executing migration                      logger=migrator id="Update alert annotations and set TEXT to empty"
INFO[09-30|14:13:55] Executing migration                      logger=migrator id="Add created time to annotation table"
INFO[09-30|14:13:55] Executing migration                      logger=migrator id="Add updated time to annotation table"
INFO[09-30|14:13:55] Executing migration                      logger=migrator id="Add index for created in annotation table"
INFO[09-30|14:13:55] Executing migration                      logger=migrator id="Add index for updated in annotation table"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="Convert existing annotations from seconds to milliseconds"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="create test_data table"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="create dashboard_version table v1"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="add index dashboard_version.dashboard_id"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="add unique index dashboard_version.dashboard_id and dashboard_version.version"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="Set dashboard version to 1 where 0"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="save existing dashboard data in dashboard_version table v1"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="alter dashboard_version.data to mediumtext v1"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="create team table"
INFO[09-30|14:13:56] Executing migration                      logger=migrator id="add index team.org_id"
INFO[09-30|14:13:57] Executing migration                      logger=migrator id="add unique index team_org_id_name"
INFO[09-30|14:13:57] Executing migration                      logger=migrator id="create team member table"
INFO[09-30|14:13:57] Executing migration                      logger=migrator id="add index team_member.org_id"
INFO[09-30|14:13:57] Executing migration                      logger=migrator id="add unique index team_member_org_id_team_id_user_id"
INFO[09-30|14:13:58] Executing migration                      logger=migrator id="Add column email to team table"
INFO[09-30|14:14:00] Executing migration                      logger=migrator id="create dashboard acl table"
INFO[09-30|14:14:01] Executing migration                      logger=migrator id="add index dashboard_acl_dashboard_id"
INFO[09-30|14:14:01] Executing migration                      logger=migrator id="add unique index dashboard_acl_dashboard_id_user_id"
INFO[09-30|14:14:01] Executing migration                      logger=migrator id="add unique index dashboard_acl_dashboard_id_team_id"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="save default acl rules in dashboard_acl table"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="create tag table"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="add index tag.key_value"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="create login attempt table"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="add index login_attempt.username"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="drop index IDX_login_attempt_username - v1"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="Rename table login_attempt to login_attempt_tmp_qwerty - v1"
INFO[09-30|14:14:02] Executing migration                      logger=migrator id="create login_attempt v2"
INFO[09-30|14:14:03] Executing migration                      logger=migrator id="create index IDX_login_attempt_username - v2"
INFO[09-30|14:14:03] Executing migration                      logger=migrator id="copy login_attempt v1 to v2"
INFO[09-30|14:14:03] Executing migration                      logger=migrator id="drop login_attempt_tmp_qwerty"
INFO[09-30|14:14:03] Executing migration                      logger=migrator id="create user auth table"
INFO[09-30|14:14:03] Executing migration                      logger=migrator id="create index IDX_user_auth_auth_module_auth_id - v1"
INFO[09-30|14:14:03] Executing migration                      logger=migrator id="alter user_auth.auth_id to length 190"
INFO[09-30|14:14:04] Created default admin user: %v           logger=sqlstore admin=nil LOG15_ERROR="Normalized odd number of arguments by adding nil"

Admin password changed successfully ✔
[root@monitoring grafana]# grafana-cli admin reset-admin-password --homepath "/usr/share/grafana" newpass
INFO[09-30|14:16:33] Connecting to DB                         logger=sqlstore dbtype=sqlite3
INFO[09-30|14:16:33] Starting DB migration                    logger=migrator

Admin password changed successfully ✔

[root@monitoring grafana]#

And after you created the database file for the password in the wrong place all of the future execution of changing the password will modify this wrongly created file and your password will not work and you’ll still get the invalid password or name.

Bonus section – manual reset the password in the database without grafana-cli

First you should find your Grafana configuration file, under CentOS 7 it is in “/etc/grafana/grafana.ini”:

[root@monitoring ~]# ps axuf|grep grafana
grafana    490  0.0  0.0 1274696 29872 ?       Ssl  14:18   0:09 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins cfg:default.paths.provisioning=/etc/grafana/provisioning

Open the file and look for lines like:

#################################### Paths ###############################
[paths]
# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
#
data = /var/lib/grafana
#################################### Database ############################
[database]
# You can configure the database connection by specifying type, host, name, user and password
# as seperate properties or as on string using the url propertie.

# 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 trippel quotes. Ex """#password;"""
password =
# Use either URL or the previous fields to configure the database
# Example: mysql://user:secret@host:port/database
url =

As you can see this configuration says the type of the database is “sqlite3” and the file of the database is in /var/lib/grafana – /var/lib/grafana/grafana.db. So execute the following to reset the password:

[root@monitorin ~]# sqlite3 /var/lib/grafana/grafana.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
alert                   dashboard_version       quota                 
alert_notification      data_source             session               
annotation              login_attempt           star                  
annotation_tag          migration_log           tag                   
api_key                 org                     team                  
dashboard               org_user                team_member           
dashboard_acl           playlist                temp_user             
dashboard_provisioning  playlist_item           test_data             
dashboard_snapshot      plugin_setting          user                  
dashboard_tag           preferences             user_auth             
sqlite> select * from user;
1|0|admin|admin@example.com|Admin|34523452daaaeeeefffw558687994560498b1c6e9a78253413363334e453459a8afb1f08b43aaa6feb3d12cb0e417b81e209|Z6ffE7yyzc|46pd5MzKYv||1|1|0|dark|2016-06-01 22:44:24|2018-09-20 08:05:51|1|2018-09-23 15:02:11
3|0|myuser@example.com|myuser@example.com|My User|099776920940da2aaafeefae1f5234505288c72345723452350fffefefedadafafdcc8338fe8498ffe665d9489ac406fdbc6|TCPPLiodsx|7czPOlNmr5||1|0|0||2018-09-21 13:07:43|2018-09-21 13:07:43|0|2018-09-21 13:19:28
sqlite> update user set password = '59acf18b94d7eb0694c61e60ce44c110c7a683ac6a8f09580d626f90f4a242000746579358d77dd9e570e83fa24faa88a8a6', salt = 'F3FAxVm33R' where login = 'admin';
sqlite> 

13 thoughts on “Reset lost admin password of Grafana server (CentOS 7)”

  1. The cli reset didn’t work as it said that admin was not a valid option.

    Tried the sqlite method which worked.

    Many thanks for the post.

  2. This is relevant for brew based grafana install on MacOS.
    This was the only method that allowed me to reset the admin password.

  3. Mine got below error, after execute update
    sqlite> select * from user;
    1|0|admin|admin@localhost||b8ee041637736fe157329ce0cd60bb343067b3ee34c177c2137946b3e38fee069316bfbb8f0dbf0b75b01e2eadb3dc3e2be2|4G4S7hvjXp|U1YZrdYbrn||1|1|0||2022-04-13 02:45:17|2022-04-26 03:42:29|1|2022-04-29 07:31:40|0|0

    sqlite> update user set password = ’59acf18b94d7eb0694c61e60ce44c110c7a683ac6a8f09580d626f90f4a242000746579358d77dd9e570e83fa24faa88a8a6′, salt = ‘F3FAxVm33R’ where login = ‘admin’;
    Error: unable to open database file

    any advice?

    1. Do you have full write access to the database file: /var/lib/grafana/grafana.db? You may have only read access to the file. Check your user permissions including the SELinux ones.

  4. It works for me with the command line :

    sudo grafana-cli –homepath “/usr/share/grafana” admin reset-admin-password –password-from-stdin

  5. I succesfully typed those commands:
    sqlite> select * from user;
    1|0|admin|admin@localhost||13bc3ec9f64718b720b7ee726699a3594cb27ca8f9ecb19b38f2a2af3f238487d57998bf9b77b24c5e9df2090f5ed9cb842c|xVVtrCjbWS|WWJ5xySE5r||1|1|0||2023-09-18 20:55:47|2023-09-18 20:55:47|0|2013-09-18 20:55:47|0|0
    sqlite> update user set password = ’59acf18b94d7eb0694c61e60ce44c110c7a683ac6a8f09580d626f90f4a242000746579358d77dd9e570e83fa24faa88a8a6′, salt = ‘F3FAxVm33R’ where login = ‘admin’;
    sqlite> select * from user;
    However, when I type admin for username and password, still getting rejected to log in. Any ideas? u.u

Leave a Reply

Your email address will not be published. Required fields are marked *