grafana 4 升級到 grafana 5錯誤處理


遇到2個錯誤:

 

1. UNIQUE KEY 問題

INFO[07-16|15:34:36] Executing migration logger=migrator id="Remove unique index org_id_slug"
EROR[07-16|15:34:36] Executing migration failed logger=migrator id="Remove unique index org_id_slug" error="Error 1091: Can't DROP 'UQE_dashboard_org_id_slug'; check that column/key exists"
EROR[07-16|15:34:36] Exec failed logger=migrator error="Error 1091: Can't DROP 'UQE_dashboard_org_id_slug'; check that column/key exists" sql="DROP INDEX `UQE_dashboard_org_id_slug` ON `dashboard`"
EROR[07-16|15:34:36] Server shutdown logger=server reason="Service init failed: Migration failed err: Error 1091: Can't DROP 'UQE_dashboard_org_id_slug'; check that column/key exists"

  

故障原因,原數據庫中的`dashboard`表沒有“UQE_dashboard_org_id_slug”這個UNIQUE KEY ,所以在刪除的時候失敗了。

 

2. Convert existing annotations from seconds to milliseconds問題

INFO[07-16|17:13:41] Executing migration                      logger=migrator id="Convert existing annotations from seconds to milliseconds"
EROR[07-16|17:13:41] Executing migration failed               logger=migrator id="Convert existing annotations from seconds to milliseconds" error="Error 1264: Out of range value for column 'epoch' at row 1"
EROR[07-16|17:13:41] Exec failed                              logger=migrator error="Error 1264: Out of range value for column 'epoch' at row 1" sql="UPDATE annotation SET epoch = (epoch*1000) where epoch < 9999999999"
EROR[07-16|17:13:41] Server shutdown                          logger=server reason="Service init failed: Migration failed err: Error 1264: Out of range value for column 'epoch' at row 1"

  

故障原因,原表annotation的字段epoch類型是int,但是新版grafana中,需要將該字段的秒轉換為毫秒,長度不夠用了,執行轉換的sql語句執行失敗。

 

解決方案:

1,導出當前grafana使用的數據庫內容:

mysqldump -uroot -hlocalhost -p grafana > grafana.sql

 

2, 編輯導出的sql文件,將int(11)替換為bigint(20)

vi grafana.sql

:%s/int(11)/int(20)/g

 

3,找到`dashboard`表的創建語句,添加UNIQUE KEY `UQE_dashboard_org_id_slug`,例如:

 

DROP TABLE IF EXISTS `dashboard`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dashboard` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `version` bigint(20) NOT NULL,
  `slug` varchar(189) COLLATE utf8mb4_unicode_ci NOT NULL,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `data` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `org_id` bigint(20) NOT NULL,
  `created` datetime NOT NULL,
  `updated` datetime NOT NULL,
  `updated_by` bigint(20) DEFAULT NULL,
  `created_by` bigint(20) DEFAULT NULL,
  `gnet_id` bigint(20) DEFAULT NULL,
  `plugin_id` varchar(189) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `UQE_dashboard_org_id_slug` (`org_id`,`slug`),
  KEY `IDX_dashboard_org_id` (`org_id`),
  KEY `IDX_dashboard_gnet_id` (`gnet_id`)
) ENGINE=InnoDB AUTO_INCREMENT=187 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

  

4, 創建新的數據庫,然后導入剛剛編輯的sql文件。

create database grafana5  DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
use grafana5
source  ./grafana.sql;

  

5, 為grafana賬號添加新數據庫授權,然后修改新版本配置文件,使用剛創建的數據庫。

然后再重新啟動grafana5,啟動后會自動進行舊數據轉換,轉換完畢訪問grafana的頁面,你會發現舊版所有內容都已經可以在新版上訪問啦。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM