MySQL or MariaDB: Column count of mysql.proc is wrong, table probably corrupted
Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corruptedShort 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.
Fix it fast
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();"2Match what you see, then jump to its fix
- 1
Error 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
The 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
Error 1805 instead of 1558, the same message textError 1805: the table was made by this version but altered or damagedFix
- 1
What does the error look like?
Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corruptedError 1558: Column count of mysql.proc is wrongError 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 -l2Fix
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 -p3Verify
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
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-upgrade2Fix
Run the upgrade again with --force, which ignores the version check.
sudo mariadb-upgrade --force3Verify
Call the stored procedure again, or run SHOW PROCEDURE STATUS.
mysql -e "SHOW PROCEDURE STATUS WHERE Db = 'mydb'"Confirmed by mariadb.com
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 --force3Verify
Restart and run the procedure again.
sudo systemctl restart mariadbConfirmed by mariadb.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
An Aria table fails with 'Read page with wrong checksum' (error 1030, code 176)
ERROR 1030 (HY000): Got error 176 "Read page with wrong checksum" from storage engine Aria
Code 176 means MariaDB's Aria engine read a data or index page whose checksum does not match, so that table file is damaged.
3 causes, each with a fixDatabases
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 fixDatabases
Laravel query fails: conversion from one collation into another is impossible
SQLSTATE[HY000]: General error: 3988 Conversion from collation utf8_unicode_ci into utf8mb4_0900_ai_ci impossible for parameter
MySQL is comparing or binding a value whose character set cannot be converted into the one on the other side.
3 causes, each with a fixDatabases
PHP cannot connect to MySQL: the connection attempt failed
Error 2003
Error 2003 means the TCP connection to MySQL never opened.
4 causes, each with a fixDatabases
The client cannot reach the MySQL or MariaDB server through its Unix socket file
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2) (MariaDB client wording)
Error 2002 means the client tried the Unix socket file named in the message and found nothing it could talk to.
4 causes, each with a fixDatabases
Saving an empty date from PHP into a MySQL DATETIME column fails
The column holds 0000-00-00 00:00:00 instead of NULL
An empty string is not NULL.
4 causes, each with a fix