This error occurs when MySQL system tables have a different number of columns than expected by the current MySQL version, typically after an incomplete upgrade. The fix is to run the mysql_upgrade utility to synchronize your system tables with your current MySQL version.
MySQL maintains internal system tables (like mysql.proc, mysql.user, mysql.func) that store metadata about stored procedures, users, and functions. These tables have a fixed structure that changes between MySQL versions. When you upgrade MySQL without properly upgrading these system tables, the running MySQL server expects a certain number of columns in these tables, but finds a different number instead. The error message typically looks like: "ERROR 1558 (HY000): Column count of mysql.<table_name> is wrong. Expected X, found Y. Created with MySQL VERSION_A, now running VERSION_B." This is a critical error because it prevents the MySQL server from accessing its own system tables, which can block basic operations like user authentication and stored procedure execution.
First, gracefully shut down the MySQL service to prevent any data corruption:
# On systemd systems (Linux)
sudo systemctl stop mysql
# Or on traditional systems
sudo service mysql stop
# On macOS with Homebrew
brew services stop [email protected]
# Or manually kill the process
sudo mysqladmin shutdownWait a few seconds to ensure the process has fully stopped before proceeding.
The mysql_upgrade utility updates MySQL system tables to match your current MySQL version. This is the primary fix for ERROR 1558:
# Standard invocation (prompts for password)
mysql_upgrade -u root -p
# Non-interactive if you have .my.cnf configured
mysql_upgrade -u root -p --password=your_password
# Force the upgrade even if tables seem compatible
mysql_upgrade -u root -p --forceThe utility will:
- Check all tables in all databases for compatibility
- Upgrade system tables to the current version
- Rebuild the privilege tables with new columns
- Clear deprecated columns and settings
After mysql_upgrade completes successfully, restart the MySQL service:
# On systemd systems
sudo systemctl start mysql
# Or on traditional systems
sudo service mysql start
# On macOS
brew services start [email protected]The server should start without errors. If you still see ERROR 1558, there may be additional corruption.
Test that MySQL is working properly and the error is resolved:
# Connect to MySQL
mysql -u root -p
# At the MySQL prompt, run:
SELECT VERSION();
SELECT COUNT(*) FROM mysql.user;
SHOW TABLES FROM mysql;If these commands execute successfully without ERROR 1558, the issue is fixed. Your databases and data remain intact.
If you're using MariaDB instead of MySQL, use the MariaDB-specific upgrade command:
# Stop MariaDB
sudo systemctl stop mariadb
# Run MariaDB upgrade utility
mariadb-upgrade -u root -p
# Restart MariaDB
sudo systemctl start mariadbIn newer versions of MariaDB/MySQL, the upgrade is performed automatically on startup if system tables are out of date.
For MySQL 8.0.16 and later: The mysql_upgrade utility has been deprecated. Instead, the MySQL server automatically performs all necessary upgrade steps on startup when it detects that system tables are out of date. Simply starting the new MySQL version with your old data directory will trigger an automatic upgrade. No restart is needed after the automatic upgrade completes.
For Docker users: If you encounter this error in a Docker container, ensure you're upgrading the base image properly:
# Stop and remove the old container
docker stop mysql_container
docker rm mysql_container
# Update to a new MySQL image
docker pull mysql:8.0.40 # or your target version
# Run the new container with your old data volume
docker run -v mysql_data:/var/lib/mysql mysql:8.0.40Backup before upgrade: While mysql_upgrade is generally safe, always have a backup before performing major version upgrades:
mysqldump -u root -p --all-databases > backup.sqlSELinux and AppArmor: If you're on a system with SELinux or AppArmor enabled, ensure the MySQL process has permission to read and write to the data directory after upgrade. If mysql_upgrade runs as root but the MySQL daemon runs as 'mysql' user, permission issues may occur.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL