Skip to content

Running mysql_upgrade on a cPanel host — when it's needed and what it actually does

mysql_upgrade is the post-package-update step that updates the system tables to the new daemon's expectations. The cPanel wizard runs it automatically, but manual triggers are sometimes necessary.

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:

  1. Runs CHECK TABLE FOR UPGRADE on every user table across every database. Tables in older formats are flagged and repaired or reformatted.
  2. 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

  1. Confirm you need to run it. If mysql_upgrade_info says 10.11.4 and SELECT VERSION() returns 10.11.4, no upgrade needed. If they differ, run upgrade.
  2. Take a backup first:
    mysqldump --all-databases --single-transaction --routines --triggers --events | gzip > /backup/pre-upgrade-$(date +%F).sql.gz
    mysql_upgrade shouldn’t break anything, but a backup is cheap insurance.
  3. Run mysql_upgrade:
    mysql_upgrade --force -u root -p
    --force runs it even if the marker says you’re already at this version. -u root -p provides 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
    ...
  4. Watch for table-level errors. If a table reports “Table upgrade required. Please do REPAIR TABLE…” run REPAIR on it:
    mysql -e "REPAIR TABLE acmecorp_legacy.old_table"
    Common for MyISAM tables from older versions; rare on InnoDB.
  5. For cPanel-specific issues, the wizard updates a different marker. After manual mysql_upgrade, run:
    /scripts/build_cpanel_rpm_versions
    /scripts/check_cpanel_rpms --targets=MySQL --fix
    To sync cPanel’s view.
  6. Restart MySQL after a major upgrade:
    systemctl restart mariadb
    Some system table changes take effect only after restart.
  7. Verify post-upgrade:
    mysql -e "SELECT VERSION()"
    mysql -e "SHOW WARNINGS"
    journalctl -u mariadb -p err --since "10 minutes ago"
    whmapi1 list_dbs | head
    No errors, dbmap intact, version matches expectation.
  8. For “mysql_upgrade can’t connect” errors, ensure /root/.my.cnf has valid credentials or provide them explicitly. After a fresh install or password reset, this file sometimes doesn’t have what mysql_upgrade needs.

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.