The error occurs because critical system tables in the mysql
database are either missing or corrupted. The key error messages indicate:
Table 'mysql.plugin' doesn't exist
Table 'mysql.host' doesn't exist
Table 'mysql.servers' doesn't exist
performance_schema tables have wrong structure
1. Stop MySQL Service
sudo service mysql stop
# Or if using systemd:
sudo systemctl stop mysql
2. Start MySQL in Recovery Mode
Run mysqld with --skip-grant-tables
to bypass privilege checks:
mysqld_safe --skip-grant-tables &
3. Reinitialize System Tables
Create a temporary SQL file (reinit.sql
) with these commands:
CREATE DATABASE IF NOT EXISTS mysql;
USE mysql;
SOURCE /usr/share/mysql/mysql_system_tables.sql;
SOURCE /usr/share/mysql/mysql_system_tables_data.sql;
# For MySQL 5.5 specific additions
SOURCE /usr/share/mysql/fill_help_tables.sql;
Then execute it:
mysql -uroot < reinit.sql
4. Repair Performance Schema
For MySQL 5.5, you'll need to rebuild the performance_schema:
mysql -uroot -e "DROP DATABASE IF EXISTS performance_schema;"
mysql -uroot -e "CREATE DATABASE performance_schema;"
mysql -uroot performance_schema < /usr/share/mysql/performance_schema.sql
If the standard files aren't available, you can manually create essential tables. Here's the minimal host
table structure:
CREATE TABLE host (
Host char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
Db char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
Select_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Insert_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Update_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Delete_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Create_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Drop_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Grant_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
References_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Index_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Alter_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Create_tmp_table_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Lock_tables_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Create_view_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Show_view_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Create_routine_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Alter_routine_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Execute_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
Trigger_priv enum('N','Y') COLLATE utf8_bin NOT NULL DEFAULT 'N',
PRIMARY KEY (Host,Db)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Host privileges';
After reconstructing the system tables:
mysql_upgrade --force
sudo service mysql restart
Check the error log for any remaining issues:
tail -f /var/log/mysql/error.log
- Always back up the mysql database before upgrades
- Consider using
mysql_upgrade --force
if standard upgrade fails - Verify the existence of system table SQL files in /usr/share/mysql/
When upgrading from MySQL 5.1 to 5.5, the mysql_upgrade
utility fails with a generic "FATAL ERROR: Upgrade failed" message. The error log reveals deeper issues with missing system tables (mysql.plugin
, mysql.host
, etc.) and performance_schema table structure mismatches.
Key error patterns appearing in loops:
ERROR: Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
ERROR: Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
ERROR: Native table 'performance_schema'.'events_waits_current' has the wrong structure
Try running mysql_upgrade with the MySQL server in safe mode:
# Stop MySQL normally
sudo service mysql stop
# Start in safe mode with grant tables disabled
mysqld_safe --skip-grant-tables --skip-networking &
# Run upgrade with force option
mysql_upgrade --force
If the above fails, we need to manually rebuild system tables. First create a backup:
# Backup existing mysql database
mysqldump --all-databases --routines --events > full_backup.sql
cp -r /var/lib/mysql /var/lib/mysql_backup
For severe corruption, we must recreate the system database:
# Stop MySQL
sudo service mysql stop
# Move old mysql database
mv /var/lib/mysql/mysql /var/lib/mysql/mysql_old
# Reinitialize data directory
mysqld --initialize-insecure --user=mysql
# Restart and secure installation
sudo service mysql start
mysql_secure_installation
After successful recovery:
- Import your user databases from backup
- Recreate users and permissions
- Verify all application functionality
For performance_schema issues, run:
mysql_upgrade --upgrade-system-tables --force
mysqlcheck --all-databases --repair --use-frm
Always:
- Create full backups before major version upgrades
- Test upgrades in staging environments
- Review MySQL upgrade documentation for version-specific notes