Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running migrations for Grafana 5.1.1 using mysql with utf8mb4 #11862

Closed
kfdm opened this issue May 8, 2018 · 4 comments
Closed

Error when running migrations for Grafana 5.1.1 using mysql with utf8mb4 #11862

kfdm opened this issue May 8, 2018 · 4 comments

Comments

@kfdm
Copy link
Contributor

kfdm commented May 8, 2018

What Grafana version are you using?

Grafana: 5.1.1

What OS are you running grafana on?

CentOS 7

What did you do?

Installed Grafana 5.1.1

What was the expected result?

Grafana 5.1.1 starts

What happened instead?

May 08 11:11:45 *** grafana-server[84530]: t=2018-05-08T11:11:45+0900 lvl=eror msg="Executing migration failed" logger=migrator id="alter user_auth.auth_id to length 255" error="Error 1709: Index column size too large. The maximum column size is 767 bytes."
May 08 11:11:45 *** grafana-server[84530]: t=2018-05-08T11:11:45+0900 lvl=eror msg="Exec failed" logger=migrator error="Error 1709: Index column size too large. The maximum column size is 767 bytes." sql="ALTER TABLE user_auth MODIFY auth_id VARCHAR(255);"

Seems like this could be related to https://github.com/grafana/grafana/pull/8483/files regarding utf8mb4
3d9b7a5#diff-e100e446139e6466b395663e9e83a731
#11784

@marefr
Copy link
Contributor

marefr commented May 8, 2018

Introduced by closing #11754. We'll try to get out a fix for this asap.

In the meantime, the workaround is to execute the following:

UPDATE migration_log SET success=1 WHERE migration_id='alter user_auth.auth_id to length 255';
ALTER TABLE user_auth MODIFY auth_id VARCHAR(190);

Thanks for reporting

@rlueckl
Copy link

rlueckl commented May 8, 2018

I'm facing the same issue. I tried alter table, but still get the same error:

mysql> describe user_auth;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| user_id     | bigint(20)   | NO   |     | NULL    |                |
| auth_module | varchar(190) | NO   | MUL | NULL    |                |
| auth_id     | varchar(100) | NO   |     | NULL    |                |
| created     | datetime     | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> alter table user_auth modify auth_id varchar(190);
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe user_auth;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| user_id     | bigint(20)   | NO   |     | NULL    |                |
| auth_module | varchar(190) | NO   | MUL | NULL    |                |
| auth_id     | varchar(190) | YES  |     | NULL    |                |
| created     | datetime     | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> 
# tail -n 4 /var/log/grafana/grafana.log
t=2018-05-08T13:47:04+0200 lvl=info msg="Executing migration" logger=migrator id="alter user_auth.auth_id to length 255"
t=2018-05-08T13:47:04+0200 lvl=eror msg="Executing migration failed" logger=migrator id="alter user_auth.auth_id to length 255" error="Error 1071: Specified key was too long; max key length is 767 bytes"
t=2018-05-08T13:47:04+0200 lvl=eror msg="Exec failed" logger=migrator error="Error 1071: Specified key was too long; max key length is 767 bytes" sql="ALTER TABLE user_auth MODIFY auth_id VARCHAR(255);"
t=2018-05-08T13:47:04+0200 lvl=eror msg="Fail to initialize orm engine" logger=sqlstore error="Sqlstore::Migration failed err: Error 1071: Specified key was too long; max key length is 767 bytes\n"

Honestly, I don't understand, why the suggestion is to change the field to VARCHAR(190) if Grafana expects/tries to change it to VARCHAR(255). Could you explain?

@marefr
Copy link
Contributor

marefr commented May 8, 2018

Sorry forgot to mention that you need to patch the migration_log table as well. Something like this should work:

UPDATE migration_log SET success=1 WHERE migration_id='alter user_auth.auth_id to length 255';
ALTER TABLE user_auth MODIFY auth_id VARCHAR(190);

Please confirm that this is working and I'll update my comment above. Thanks

@rlueckl
Copy link

rlueckl commented May 8, 2018

Manually updating the migration_log table worked, Grafana 5.1.1 starts now. Thanks!

marefr added a commit that referenced this issue May 9, 2018
ryantxu added a commit to NatelEnergy/grafana that referenced this issue May 9, 2018
* grafana/master:
  changelog: add notes about closing grafana#11862, grafana#11656
  Fix dependencies on Node v10
  Update dashboard.md
  Adding a user in a specified organisation uses the admin API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants