[ZBX-20905] Zabbix server upgrade from 4.0 to 6.0.3 failed on MySQL 8 due to utf8mb4 character set Created: 2022 Apr 16  Updated: 2024 Aug 28  Resolved: 2022 May 10

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Documentation (D)
Affects Version/s: 6.0.3
Fix Version/s: 6.0.5rc1, 6.2.0beta1, 6.2 (plan)

Type: Documentation task Priority: Major
Reporter: Little Martian Assignee: Martins Valkovskis
Resolution: Fixed Votes: 0
Labels: database
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File server.log    
Issue Links:
Duplicate
duplicates ZBXNEXT-3706 mysql utf8 vs utf8mb4 Closed
Sub-task
part of ZBX-20165 Database upgrade failed, Zabbix v. 5.... Closed
Team: Team A
Sprint: Sprint 87 (Apr 2022)
Story Points: 0.25

 Description   

Steps to reproduce:

  1. Export 4.0 schema as sql script (mysql 5.7)
  2. Change character set to utf8mbr, collation utf8mb4_bin int the sql script
  3. Create schema using the above sql script in a new database (mysql 8.0.26)
  4. Export 4.0 data from old database (mysql 5.7)
  5. Import 4.0 data into new database (mysql 8.0.26)
  6. Start zabbix_server process
  7. Zabbix server tries to upgrade schema and fails: [Z3005] query failed: [1071] Specified key was too long; max key length is 3072 bytes [create index items_1 on items (hostid,key_(1021))]

Result:
See log file...
Expected:
Zabbix server should be aware of the limitations on index keys on MySQL 8+ when using utf8mb4 character set (max key length is 3072/4=768)



 Comments   
Comment by Edgar Akhmetshin [ 2022 Apr 18 ]

Zabbix supports utf8mb4 starting from 6.0 (ZBXNEXT-3706). MySQL supports utf8mb4 starting from =>5.5.3 series (2010), so schema can be converted in-place before moving data or using the same server.

Old databases should be checked/prepared/converted accordingly by DBA:
https://www.zabbix.com/documentation/6.0/en/manual/appendix/install/db_charset_coll
https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-conversion.html

Regards,
Edgar

Comment by Little Martian [ 2022 Apr 18 ]

I tryed converting the database using the script provided. It executed successfully, converted all tables.

Starting zabbix_server 6.0.3 after that, still fails with the same error:

655424:20220418:142124.670 completed 13% of database upgrade
655424:20220418:142128.759 [Z3005] query failed: [1071] Specified key was too long; max key length is 3072 bytes [create index items_1 on items (hostid,key_(1021))]
655424:20220418:142128.760 database upgrade failed

The problem seems to be in src/libs/zbxdbupgrade/dbuprgade_4050.c:

static int    DBpatch_4050004(void)
{
#ifdef HAVE_MYSQL
    return DBcreate_index("items", "items_1", "hostid,key_(1021)", 0);
#else
    return DBcreate_index("items", "items_1", "hostid,key_", 0);
#endif
}

It should be:

static int    DBpatch_4050004(void)
{
#ifdef HAVE_MYSQL
    return DBcreate_index("items", "items_1", "hostid,key_(768)", 0);
#else
    return DBcreate_index("items", "items_1", "hostid,key_", 0);
#endif
}

It is also present in dbupgrade_5030.c:

static int    DBpatch_5030170(void)
{
#ifdef HAVE_MYSQL
    return DBcreate_index("items", "items_8", "key_(1024)", 0);
#else
    return DBcreate_index("items", "items_8", "key_", 0);
#endif
}

It should be:

static int    DBpatch_5030170(void)
{
#ifdef HAVE_MYSQL
    return DBcreate_index("items", "items_8", "key_(768)", 0);
#else
    return DBcreate_index("items", "items_8", "key_", 0);
#endif
}

 

Comment by Little Martian [ 2022 Apr 18 ]

It seems to work if:

  • Initial database migration is done in utf8 (utf8mb3)
  • start zabbix_server and let it upgrade the schema
  • execute utf8mb4 conversion

As the db patch in dbupgrade_5050.c drops items_1 index and recreate it correctly with hostid,key_(764) and also drops index items_8 and recreate it key_(768)

Comment by Edgar Akhmetshin [ 2022 Apr 19 ]

Yes, correct. 5.0 knows only utf8mb3, it looks like we need provide guideline in our documentation.

Comment by Martins Valkovskis [ 2022 Apr 27 ]

Updated documentation for executing utfmb4 conversion mentions in a note the need to upgrade the server and database schema to 6.0.x before attempting utfmb4 conversion.

Additional improvement: "What's new" for 6.0 now points to the instructions for utf8mb4 conversion.

Comment by Venky [ 2023 Jun 12 ]

Hi,

We have same issue. After Zabbix upgrade from 3.4.9 to 6.0.18 database conversion failed with below error,

    [Z3005] query failed: [1071] Specified key was too long; max key length is 3072 bytes [alter table `items` modify `key_` varchar(2048) default '' not null].

We have default database schema is latin1_swedish_ci. We have directly upgraded Zabbix from 3.4.9 to 6.0.18 without any issue.  After Zabbix upgrade tried to execute utf8mb4 conversion but table conversion failed with above error,   

   [Z3005] query failed: [1071] Specified key was too long; max key length is 3072 bytes [alter table `items` modify `key_` varchar(2048) default '' not null]. 

 

https://www.zabbix.com/documentation/6.0/en/manual/appendix/install/db_charset_coll

Executed below command and then ran the database migration again. Database migration completed without any issue.  

ALTER TABLE zabbix.items MODIFY COLUMN key_ VARCHAR(764) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin not null default ' ';

 

Query is modifying table `items` modify `key_` varchar(2048) to key_ VARCHAR(764) will cause any issue to Zabbix database? Any help appreciated. 

 

 Mysql version  8.0.33
zabbix version 6.0.18

Generated at Sat Jul 05 07:59:57 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.