Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

MySQL or MariaDB: Column count of mysql.proc is wrong, table probably corrupted

ErrorColumn count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted

Short answer

The mysql.proc system table has a different number of columns than the running server expects. It is almost never real corruption. The server was upgraded without running the upgrade tool, or an old mysql database was restored into a newer server. Run mysql_upgrade (mariadb-upgrade on MariaDB) as an admin and restart.

  • Applies to MariaDB 10.11, MariaDB 11.4, MySQL 5.7, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the server version and the two column counts in the message. Then check which program started the server, so you run the matching upgrade tool.

    mysql --version
    sudo mariadb -e "SELECT VERSION();"
  2. 2Match what you see, then jump to its fix

    1. 1Error 1558, and the message appeared right after a package upgrade or a move to a new major versionThe server was upgraded but the upgrade tool never ranFix
    2. 2The error started right after you restored a full dump or copied the data directory from an older serverAn old mysql database dump was restored into a newer serverFix
    3. 3Error 1805 instead of 1558, the same message textError 1805: the table was made by this version but altered or damagedFix

What does the error look like?

  • Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted
  • Error 1558: Column count of mysql.proc is wrong
  • Error 1805: Column count of mysql.proc is wrong

Cause 1 of 3

The server was upgraded but the upgrade tool never ran

1Check

A table in the mysql system database was created by an older server and has fewer columns than the new one expects. Major upgrades change system tables, and a tool must apply those changes.

mysql --version
sudo mariadb -e "SHOW COLUMNS FROM mysql.proc" | wc -l

2Fix

Back up your databases, then run the upgrade tool as a user with all privileges. On MariaDB it is mariadb-upgrade (formerly mysql_upgrade); with unix_socket authentication run it with sudo. On MySQL 5.7 use mysql_upgrade with an administrative account.

# MariaDB
sudo mariadb-upgrade
# MySQL 5.7
mysql_upgrade -u root -p

3Verify

Restart the server so the table changes take effect, then call the stored procedure again.

sudo systemctl restart mariadb
mysql -e "SHOW PROCEDURE STATUS WHERE Db = 'mydb'"

Confirmed by mariadb.com

Did this fix it?

Cause 2 of 3

An old mysql database dump was restored into a newer server

1Check

Restoring a dump of the mysql database brings back the old system tables. The recorded version file may already say the server is current, so the tool may report that nothing needs upgrading.

sudo mariadb-upgrade

2Fix

Run the upgrade again with --force, which ignores the version check.

sudo mariadb-upgrade --force

3Verify

Call the stored procedure again, or run SHOW PROCEDURE STATUS.

mysql -e "SHOW PROCEDURE STATUS WHERE Db = 'mydb'"

Confirmed by mariadb.com

Did this fix it?

Cause 3 of 3

Error 1805: the table was made by this version but altered or damaged

1Check

With 1805 the table was created by the running version, so a missed upgrade is not the cause. It may have been changed by hand or damaged.

sudo mariadb -e "SHOW COLUMNS FROM mysql.proc"

2Fix

MariaDB documents that mariadb-upgrade --force can also repair the table structure in this case. Back up first.

sudo mariadb-upgrade --force

3Verify

Restart and run the procedure again.

sudo systemctl restart mariadb

Confirmed by mariadb.com

Did this fix it?

How do I stop it coming back?

  • After every major-version upgrade of MariaDB or MySQL 5.7, run the upgrade tool as part of the same maintenance window.
  • Take a backup of all databases before running the upgrade tool, as the documentation advises.
  • Do not restore the mysql system database from an older server into a newer one; dump users and grants separately.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Databases

Laravel bulk insert fails with 'too many placeholders'

SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders

Laravel sends one placeholder per value, so one insert of many rows times many columns, or a whereIn with a huge list, creates a statement MySQL refuses.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.