Grafana sqlite3 database admin passwd change

Hello,

I am trying to change the default password for the “admin” using the new “grafana-cli admin reset-admin-password passwd_name” feature. First time i ran the command i got the following error message:


“ubuntu@hostname:~$ sudo grafana-cli admin reset-admin-password test123test
Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath”

Then i change the homepath after looking at the “/etc/init.d/grafana-server” ( GRAFANA_HOME=/usr/share/grafana
). First time i ran the command i got:


ubuntu@hostname:/usr/share/grafana$ sudo grafana-cli admin reset-admin-password test123test
INFO[03-24|10:17:17] Initializing DB logger=sqlstore dbtype=sqlite3
INFO[03-24|10:17:17] Starting DB migration logger=migrator
INFO[03-24|10:17:17] Executing migration logger=migrator id="create migration_log table"
INFO[03-24|10:17:17] Executing migration logger=migrator id="create user table"
INFO[03-24|10:17:17] Executing migration logger=migrator id="add unique index user.login"
INFO[03-24|10:17:17] Executing migration logger=migrator id="add unique index user.email"
INFO[03-24|10:17:18] Executing migration logger=migrator id="drop index UQE_user_login - v1"
INFO[03-24|10:17:18] Executing migration logger=migrator id="drop index UQE_user_email - v1"
INFO[03-24|10:17:18] Executing migration logger=migrator id="Rename table user to user_v1 - v1"
INFO[03-24|10:17:18] Executing migration logger=migrator id="create user table v2"
INFO[03-24|10:17:18] Executing migration logger=migrator id="create index UQE_user_login - v2"
INFO[03-24|10:17:18] Executing migration logger=migrator id="create index UQE_user_email - v2"
INFO[03-24|10:17:18] Executing migration logger=migrator id="copy data_source v1 to v2"
INFO[03-24|10:17:18] Executing migration logger=migrator id="Drop old table user_v1"
INFO[03-24|10:17:18] Executing migration logger=migrator id="Add column help_flags1 to user table"
INFO[03-24|10:17:18] Executing migration logger=migrator id="create temp user table v1-7"
INFO[03-24|10:17:18] Executing migration logger=migrator id="create index IDX_temp_user_email - v1-7"
INFO[03-24|10:17:18] Executing migration logger=migrator id="create index IDX_temp_user_org_id - v1-7"
INFO[03-24|10:17:18] Executing migration logger=migrator id="create index IDX_temp_user_code - v1-7"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create index IDX_temp_user_status - v1-7"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create star table"
INFO[03-24|10:17:19] Executing migration logger=migrator id="add unique index star.user_id_dashboard_id"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create org table v1"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create index UQE_org_name - v1"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create org_user table v1"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create index IDX_org_user_org_id - v1"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create index UQE_org_user_org_id_user_id - v1"
INFO[03-24|10:17:19] Executing migration logger=migrator id="copy data account to org"
INFO[03-24|10:17:19] Skipping migration condition not fulfilled logger=migrator id="copy data account to org"
INFO[03-24|10:17:19] Executing migration logger=migrator id="copy data account_user to org_user"
INFO[03-24|10:17:19] Skipping migration condition not fulfilled logger=migrator id="copy data account_user to org_user"
INFO[03-24|10:17:19] Executing migration logger=migrator id="Drop old table account"
INFO[03-24|10:17:19] Executing migration logger=migrator id="Drop old table account_user"
INFO[03-24|10:17:19] Executing migration logger=migrator id="create dashboard table"
INFO[03-24|10:17:19] Executing migration logger=migrator id="add index dashboard.account_id"
INFO[03-24|10:17:19] Executing migration logger=migrator id="add unique index dashboard_account_id_slug"
INFO[03-24|10:17:20] Executing migration logger=migrator id="create dashboard_tag table"
INFO[03-24|10:17:20] Executing migration logger=migrator id="add unique index dashboard_tag.dasboard_id_term"
INFO[03-24|10:17:20] Executing migration logger=migrator id="drop index UQE_dashboard_tag_dashboard_id_term - v1"
INFO[03-24|10:17:20] Executing migration logger=migrator id="Rename table dashboard to dashboard_v1 - v1"
INFO[03-24|10:17:20] Executing migration logger=migrator id="create dashboard v2"
INFO[03-24|10:17:20] Executing migration logger=migrator id="create index IDX_dashboard_org_id - v2"
INFO[03-24|10:17:20] Executing migration logger=migrator id="create index UQE_dashboard_org_id_slug - v2"
INFO[03-24|10:17:20] Executing migration logger=migrator id="copy dashboard v1 to v2"
INFO[03-24|10:17:21] Executing migration logger=migrator id="drop table dashboard_v1"
INFO[03-24|10:17:21] Executing migration logger=migrator id="alter dashboard.data to mediumtext v1"
INFO[03-24|10:17:21] Executing migration logger=migrator id="Add column updated_by in dashboard - v2"
INFO[03-24|10:17:21] Executing migration logger=migrator id="Add column created_by in dashboard - v2"
INFO[03-24|10:17:21] Executing migration logger=migrator id="Add column gnetId in dashboard"
INFO[03-24|10:17:21] Executing migration logger=migrator id="Add index for gnetId in dashboard"
INFO[03-24|10:17:21] Executing migration logger=migrator id="Add column plugin_id in dashboard"
INFO[03-24|10:17:21] Executing migration logger=migrator id="Add index for plugin_id in dashboard"
INFO[03-24|10:17:21] Executing migration logger=migrator id="Add index for dashboard_id in dashboard_tag"
INFO[03-24|10:17:21] Executing migration logger=migrator id="create data_source table"
INFO[03-24|10:17:21] Executing migration logger=migrator id="add index data_source.account_id"
INFO[03-24|10:17:21] Executing migration logger=migrator id="add unique index data_source.account_id_name"
INFO[03-24|10:17:22] Executing migration logger=migrator id="drop index IDX_data_source_account_id - v1"
INFO[03-24|10:17:22] Executing migration logger=migrator id="drop index UQE_data_source_account_id_name - v1"
INFO[03-24|10:17:22] Executing migration logger=migrator id="Rename table data_source to data_source_v1 - v1"
INFO[03-24|10:17:22] Executing migration logger=migrator id="create data_source table v2"
INFO[03-24|10:17:22] Executing migration logger=migrator id="create index IDX_data_source_org_id - v2"
INFO[03-24|10:17:22] Executing migration logger=migrator id="create index UQE_data_source_org_id_name - v2"
INFO[03-24|10:17:22] Executing migration logger=migrator id="copy data_source v1 to v2"
INFO[03-24|10:17:22] Executing migration logger=migrator id="Drop old table data_source_v1 #2"
INFO[03-24|10:17:22] Executing migration logger=migrator id="Add column with_credentials"
INFO[03-24|10:17:22] Executing migration logger=migrator id="Add secure json data column"
INFO[03-24|10:17:22] Executing migration logger=migrator id="create api_key table"
INFO[03-24|10:17:22] Executing migration logger=migrator id="add index api_key.account_id"
INFO[03-24|10:17:22] Executing migration logger=migrator id="add index api_key.key"
INFO[03-24|10:17:23] Executing migration logger=migrator id="add index api_key.account_id_name"
INFO[03-24|10:17:23] Executing migration logger=migrator id="drop index IDX_api_key_account_id - v1"
INFO[03-24|10:17:23] Executing migration logger=migrator id="drop index UQE_api_key_key - v1"
INFO[03-24|10:17:23] Executing migration logger=migrator id="drop index UQE_api_key_account_id_name - v1"
INFO[03-24|10:17:23] Executing migration logger=migrator id="Rename table api_key to api_key_v1 - v1"
INFO[03-24|10:17:23] Executing migration logger=migrator id="create api_key table v2"
INFO[03-24|10:17:23] Executing migration logger=migrator id="create index IDX_api_key_org_id - v2"
INFO[03-24|10:17:23] Executing migration logger=migrator id="create index UQE_api_key_key - v2"
INFO[03-24|10:17:23] Executing migration logger=migrator id="create index UQE_api_key_org_id_name - v2"
INFO[03-24|10:17:23] Executing migration logger=migrator id="copy api_key v1 to v2"
INFO[03-24|10:17:23] Executing migration logger=migrator id="Drop old table api_key_v1"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create dashboard_snapshot table v4"
INFO[03-24|10:17:24] Executing migration logger=migrator id="drop table dashboard_snapshot_v4 #1"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create dashboard_snapshot table v5 #2"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create index UQE_dashboard_snapshot_key - v5"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create index UQE_dashboard_snapshot_delete_key - v5"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create index IDX_dashboard_snapshot_user_id - v5"
INFO[03-24|10:17:24] Executing migration logger=migrator id="alter dashboard_snapshot to mediumtext v2"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create quota table v1"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create index UQE_quota_org_id_user_id_target - v1"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create plugin_setting table"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create index UQE_plugin_setting_org_id_plugin_id - v1"
INFO[03-24|10:17:24] Executing migration logger=migrator id="Add column plugin_version to plugin_settings"
INFO[03-24|10:17:24] Executing migration logger=migrator id="create session table"
INFO[03-24|10:17:25] Executing migration logger=migrator id="Drop old table playlist table"
INFO[03-24|10:17:25] Executing migration logger=migrator id="Drop old table playlist_item table"
INFO[03-24|10:17:25] Executing migration logger=migrator id="create playlist table v2"
INFO[03-24|10:17:25] Executing migration logger=migrator id="create playlist item table v2"
INFO[03-24|10:17:25] Executing migration logger=migrator id="drop preferences table v2"
INFO[03-24|10:17:25] Executing migration logger=migrator id="drop preferences table v3"
INFO[03-24|10:17:25] Executing migration logger=migrator id="create preferences table v3"
INFO[03-24|10:17:25] Executing migration logger=migrator id="create alert table v1"
INFO[03-24|10:17:25] Executing migration logger=migrator id="add index alert org_id & id "
INFO[03-24|10:17:25] Executing migration logger=migrator id="add index alert state"
INFO[03-24|10:17:25] Executing migration logger=migrator id="add index alert dashboard_id"
INFO[03-24|10:17:25] Executing migration logger=migrator id="create alert_notification table v1"
INFO[03-24|10:17:26] Executing migration logger=migrator id="Add column is_default"
INFO[03-24|10:17:26] Executing migration logger=migrator id="add index alert_notification org_id & name"
INFO[03-24|10:17:26] Executing migration logger=migrator id="Drop old annotation table v4"
INFO[03-24|10:17:26] Executing migration logger=migrator id="create annotation table v5"
INFO[03-24|10:17:26] Executing migration logger=migrator id="add index annotation 0 v3"
INFO[03-24|10:17:26] Executing migration logger=migrator id="add index annotation 1 v3"
INFO[03-24|10:17:26] Executing migration logger=migrator id="add index annotation 2 v3"
INFO[03-24|10:17:26] Executing migration logger=migrator id="add index annotation 3 v3"
INFO[03-24|10:17:26] Executing migration logger=migrator id=“add index annotation 4 v3”

Error: Could not read user from database. Error: User not found

NAME:
Grafana cli admin reset-admin-password - reset-admin-password

USAGE:
Grafana cli admin reset-admin-password [arguments…]

Then every time i try to rerun the same command i get the following:


"
ubuntu@hostname:/usr/share/grafana$ sudo grafana-cli admin reset-admin-password test123test
INFO[03-24|11:09:35] Initializing DB logger=sqlstore dbtype=sqlite3
INFO[03-24|11:09:35] Starting DB migration logger=migrator
INFO[03-24|11:09:35] Executing migration logger=migrator id="copy data account to org"
INFO[03-24|11:09:35] Skipping migration condition not fulfilled logger=migrator id="copy data account to org"
INFO[03-24|11:09:35] Executing migration logger=migrator id="copy data account_user to org_user"
INFO[03-24|11:09:35] Skipping migration condition not fulfilled logger=migrator id=“copy data account_user to org_user”

Error: Could not read user from database. Error: User not found

NAME:
Grafana cli admin reset-admin-password - reset-admin-password

USAGE:
Grafana cli admin reset-admin-password [arguments…]
"

I tried to change the ubuntu user to “grafana” and execute the command but i don’t seem to succeed.
I tried on these versions: “4.1.1-1484211277” “4.1.2-1486989747” “4.2.0” “4.3.0-7355pre1”

What am i doing wrong?

Thank you

Does running the cli tool with the reset command start the server - that seems strange? Is your Grafana working or is your sqlite db corrupted?

Other questions?

  • Have you tried it without the sudo?
  • Does the admin user exist? You haven’t removed it or renamed it? Or made other changes?

Hi,

Grafana is working fine, i am provisioning whole installation with Ansible and i tested on existing/fresh installation.
Tried without the sudo and also the admin user exists.
Tried with Grafana started and stopped… still the above result…

Maybe you should have mentioned that this was an Ansible script from the start as your question was hard to understand otherwise. It looks like you are executing the CLI tool before Grafana has started.

When Grafana starts then this is the log output:

INFO[04-12|18:11:22] Starting Grafana         logger=main version=4.1.0 commit=NA compiled=2017-04-12T18:11:22+0200
<removed some lines here>
INFO[04-12|18:11:22] Initializing DB          logger=sqlstore dbtype=sqlite3
INFO[04-12|18:11:22] Starting DB migration    logger=migrator

You need to wait until Grafana is running before running CLI commands against it.

Hi,
I did not mentioned because was not relevant, i use Ansible to install, import datasources and dashboards. This has working in the last 6 months. Now i wanted to change the admin password from Ansible also but the tests from above are from manually running the commands… i did not got to the Ansible automation part because the manual part did not worked…

Then I need to double check some facts here.

  1. Your Grafana server is started and accepting requests
  2. When you run the command sudo grafana-cli admin reset-admin-password test123test, the Grafana server either restarts or starts executing database migrations:[quote=“m4rc, post:1, topic:234”]
    ubuntu@hostname:/usr/share/grafana$ sudo grafana-cli admin reset-admin-password test123test
    INFO[03-24|10:17:17] Initializing DB logger=sqlstore dbtype=sqlite3
    INFO[03-24|10:17:17] Starting DB migration logger=migrator
    [/quote]

Is that correct?

Yes, Grafana was started.

Now i retried again:

ubuntu@xxxx:~$ sudo grafana-cli admin reset-admin-password test123test
Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath


From HOMEPATH using sudo:

ubuntu@xxx:/usr/share/grafana$ sudo grafana-cli admin reset-admin-password test123test
INFO[04-18|10:12:26] Initializing DB logger=sqlstore dbtype=sqlite3
INFO[04-18|10:12:26] Starting DB migration logger=migrator
INFO[04-18|10:12:26] Executing migration logger=migrator id="copy data account to org"
INFO[04-18|10:12:26] Skipping migration condition not fulfilled logger=migrator id="copy data account to org"
INFO[04-18|10:12:27] Executing migration logger=migrator id="copy data account_user to org_user"
INFO[04-18|10:12:27] Skipping migration condition not fulfilled logger=migrator id=“copy data account_user to org_user”

Error: Could not read user from database. Error: User not found

NAME:
Grafana cli admin reset-admin-password - reset-admin-password

USAGE:
Grafana cli admin reset-admin-password [arguments…]

Without sudo:

ubuntu@xxx:/usr/share/grafana$ grafana-cli admin reset-admin-password test123test
INFO[04-18|10:14:12] Initializing DB logger=sqlstore dbtype=sqlite3
FileLogWriter("/usr/share/grafana/data/log/grafana.log"): Rotate: rename /usr/share/grafana/data/log/grafana.log /usr/share/grafana/data/log/grafana.log.2017-04-18.001: permission denied

INFO[04-18|10:14:12] Starting DB migration logger=migrator
FileLogWriter("/usr/share/grafana/data/log/grafana.log"): Rotate: rename /usr/share/grafana/data/log/grafana.log /usr/share/grafana/data/log/grafana.log.2017-04-18.001: permission denied

INFO[04-18|10:14:12] Executing migration logger=migrator id=“copy data account to org"
FileLogWriter(”/usr/share/grafana/data/log/grafana.log"): Rotate: rename /usr/share/grafana/data/log/grafana.log /usr/share/grafana/data/log/grafana.log.2017-04-18.001: permission denied

INFO[04-18|10:14:12] Skipping migration condition not fulfilled logger=migrator id=“copy data account to org"
FileLogWriter(”/usr/share/grafana/data/log/grafana.log"): Rotate: rename /usr/share/grafana/data/log/grafana.log /usr/share/grafana/data/log/grafana.log.2017-04-18.001: permission denied

INFO[04-18|10:14:12] Executing migration logger=migrator id=“copy data account_user to org_user"
FileLogWriter(”/usr/share/grafana/data/log/grafana.log"): Rotate: rename /usr/share/grafana/data/log/grafana.log /usr/share/grafana/data/log/grafana.log.2017-04-18.001: permission denied

INFO[04-18|10:14:12] Skipping migration condition not fulfilled logger=migrator id=“copy data account_user to org_user"
FileLogWriter(”/usr/share/grafana/data/log/grafana.log"): Rotate: rename /usr/share/grafana/data/log/grafana.log /usr/share/grafana/data/log/grafana.log.2017-04-18.001: permission denied

Error: Could not read user from database. Error: User not found

NAME:
Grafana cli admin reset-admin-password - reset-admin-password

USAGE:
Grafana cli admin reset-admin-password [arguments…]

I just logged in succ using the default user and passwd: admin admin ! I can see all my dashboards working fine.

After investigating this a bit more, the reset-admin command is a bit special and bit buggy. It works by starting a Grafana instance and because of that it needs to know where the config file is:

But there is a bug here so the homepath argument does not work.

This command is only supposed to be used when you have lost your admin password. I would recommend using the API instead → User HTTP API | Grafana documentation. Login with basic auth using the admin account and the default password.

Here is how to do it with curl:

curl -X PUT -H "Content-Type: application/json" -d '{
  "oldPassword": "admin",
  "newPassword": "newpass",
  "confirmNew": "newpass"
}' http://admin:admin@community.grafana.com/api/user/password

Just pushed a fix for the homepath cmd arg bug: https://github.com/grafana/grafana/commit/6ec1d16327c9514e62b0c9c2ca93f6fa3b2aade0

Okay, i tried with curl and worked fine.

Thank you

I have the same problem.
But I did an operation.
I deleted the admin user on the page


I clicked X.
How should I add admin back

@xuebaba did you get your admin user back? It should not be possible to delete the last admin user - Grafana should try and stop you.

@daniellee unfortuanately, you CAN delete the super admin when you have a normal admin user, I think it’s a bug.

the solution is also simple, create the user with email admin@localhost.