After a MariaDB or MySQL package update, the running daemon may be a new version while the system tables in the mysql schema are still in the old version’s format. The mismatch usually shows as warnings in the error log (“table needs upgrade”) or, on system table writes, hard failures. mysql_upgrade is the tool that updates the system tables to the new format. cPanel’s MySQL/MariaDB Upgrade wizard runs it automatically, but a yum-update outside the wizard, or a wizard run that timed out, leaves you needing to run it manually.
What’s happening
The mysql schema (system database) contains tables that the daemon reads at startup — mysql.user, mysql.db, mysql.tables_priv, mysql.plugin, mysql.proxies_priv, and so on. Across versions, columns are added, removed, or repurposed. The daemon expects the current schema; the tables on disk may be older.
mysql_upgrade does two things:
- Runs
CHECK TABLE FOR UPGRADEon every user table across every database. Tables in older formats are flagged and repaired or reformatted. - Updates the system schema to the current version. Adds columns, fixes defaults, runs any required migrations.
It’s idempotent — running it on already-upgraded tables is fast and harmless. It must be run as root or another user with privileges across all databases.
How to verify
mysql -e "SELECT VERSION()"
mysql -e "SHOW TABLE STATUS FROM mysql"
ls -la /var/lib/mysql/mysql_upgrade_info # marker file showing last upgrade version
journalctl -u mariadb | grep -i "upgrade\|needs upgrade" | tail -20
rpm -q --queryformat "%{INSTALLTIME}\n" MariaDB-server # when MariaDB was last installed
The marker file /var/lib/mysql/mysql_upgrade_info contains the last upgraded version. If its mtime is older than the MariaDB install time, you have an upgrade gap.
The fix
- Confirm you need to run it. If
mysql_upgrade_infosays 10.11.4 andSELECT VERSION()returns 10.11.4, no upgrade needed. If they differ, run upgrade. - Take a backup first:
mysqldump --all-databases --single-transaction --routines --triggers --events | gzip > /backup/pre-upgrade-$(date +%F).sql.gzmysql_upgradeshouldn’t break anything, but a backup is cheap insurance. - Run mysql_upgrade:
mysql_upgrade --force -u root -p--forceruns it even if the marker says you’re already at this version.-u root -pprovides credentials; you can also use--user=root --password=...non-interactively. Output streams each database and each table:acmecorp_wp.wp_options OK acmecorp_wp.wp_posts OK mysql.user OK ... - Watch for table-level errors. If a table reports “Table upgrade required. Please do REPAIR TABLE…” run REPAIR on it:
Common for MyISAM tables from older versions; rare on InnoDB.mysql -e "REPAIR TABLE acmecorp_legacy.old_table" - For cPanel-specific issues, the wizard updates a different marker. After manual mysql_upgrade, run:
To sync cPanel’s view./scripts/build_cpanel_rpm_versions /scripts/check_cpanel_rpms --targets=MySQL --fix - Restart MySQL after a major upgrade:
Some system table changes take effect only after restart.systemctl restart mariadb - Verify post-upgrade:
No errors, dbmap intact, version matches expectation.mysql -e "SELECT VERSION()" mysql -e "SHOW WARNINGS" journalctl -u mariadb -p err --since "10 minutes ago" whmapi1 list_dbs | head - For “mysql_upgrade can’t connect” errors, ensure
/root/.my.cnfhas valid credentials or provide them explicitly. After a fresh install or password reset, this file sometimes doesn’t have whatmysql_upgradeneeds.
For environments where MySQL/MariaDB upgrades happen frequently and the system table consistency needs to be guaranteed, Stack Harbor’s WHM server management team scripts post-upgrade mysql_upgrade runs and validates the marker file against the daemon version after every package operation.