Fix for MariaDb Docker "incorrect definition of table" errors

Cover Image for Fix for MariaDb Docker "incorrect definition of table" errors
Sergej Brazdeikis
Sergej Brazdeikis

I recently upgraded MariaDB Docker image, and everything went well because everything worked. It was until I checked the logs:

... 2022-10-26 19:30:12 17 [ERROR] Incorrect definition of table mysql.column_stats: expected column 'histogram' at position 10 to have type longblob, found type varbinary(255). 2022-10-26 19:30:12 17 [ERROR] Incorrect definition of table mysql.column_stats: expected column 'hist_type' at position 9 to have type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB'), found type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB'). ...

I was confused, and then I found the fix I needed. Add this ENV variable to fix it:

MARIADB_AUTO_UPGRADE: '1'

for me it did fix the issue. Note:** Backup your data first!** Read further if you want to learn what it does :)

I used mariadb:latest image from official DockerHub

MARIADB_AUTO_UPGRADE explained

After quick checking, I found the explanation on GitHub repo here:

Set MARIADB_AUTO_UPGRADE to a non-empty value to have the entrypoint check whether mysql_upgrade/mariadb-upgrade needs to run, and if so, run the upgrade before starting the MariaDB server.

Before the upgrade, a backup of the system database is created in the top of the datadir with the name system_mysql_backup_*.sql.zst. This backup process can be disabled with by setting MARIADB_DISABLE_UPGRADE_BACKUP to a non-empty value.

What MARIADB_AUTO_UPGRADE actually does

The repository for the docker image is here

And here is a snippet of what it does (permalink to Maria DB 10.10)

mysql_note "Starting temporary server" docker_temp_server_start "$@" --skip-grant-tables \ --loose-innodb_buffer_pool_dump_at_shutdown=0 \ --skip-slave-start mysql_note "Temporary server started." docker_mariadb_backup_system mysql_note "Starting mariadb-upgrade" mariadb-upgrade --upgrade-system-tables mysql_note "Finished mariadb-upgrade" mysql_note "Stopping temporary server" docker_temp_server_stop mysql_note "Temporary server stopped"

So as simple as it is, it does upgrade :)

Keep your data safe, do backup and test your backups! #peace

Sergej Brazdeikis
Sergej Brazdeikis