How to Fix “Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist” Error in MySQL 5.5 on Windows


2 views

This classic MySQL privilege table error typically occurs when the mysql system database is corrupted or missing critical tables. The specific error sequence you're seeing:

Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
Can't open the mysql.plugin table. Please run mysql_upgrade to create it

indicates that the fundamental grant tables required for MySQL authentication are damaged or absent.

Before addressing the privilege tables, we need to resolve the port conflict you mentioned:

Can't start server: Bind on TCP/IP port: No such file or directory
Do you already have another mysqld server running on port: 3306?

First verify no other MySQL instances are running:

netstat -ano | findstr 3306
taskkill /F /PID [PID_from_netstat]

Here's a step-by-step recovery method that's worked for many Windows MySQL installations:

1. Stop all MySQL services:
   net stop mysql

2. Backup your data directory (typically C:\ProgramData\MySQL\MySQL Server 5.5\data)
   xcopy /E /I /H "C:\ProgramData\MySQL\MySQL Server 5.5\data" "C:\MySQL_Backup"

3. Run MySQL in recovery mode:
   mysqld --skip-grant-tables --console

4. In another command prompt, initialize system tables:
   mysql_install_db --datadir="C:\ProgramData\MySQL\MySQL Server 5.5\data"

5. Restart MySQL normally and run:
   mysql_upgrade -u root -p

If the standard recovery fails, try this advanced technique:

# Create temporary my.cnf with special privileges
[mysqld]
skip-grant-tables
skip-networking
datadir=C:/ProgramData/MySQL/MySQL Server 5.5/data

# Initialize database structure
mysqld --defaults-file=my.cnf --initialize-insecure

# Then run the upgrade
mysql_upgrade --force -u root

To avoid recurrence:

  • Regularly back up the mysql database schema
  • Use CHECK TABLE periodically on system tables
  • Consider migrating to newer MySQL versions (5.5 reached EOL in 2018)

For stubborn cases, this nuclear option works:

1. Uninstall MySQL completely
2. Manually delete the Program Files and ProgramData folders
3. Run CCleaner to remove registry entries
4. Reinstall using the .zip package instead of installer

When your MySQL service fails to start with errors about missing system tables (mysql.host, mysql.plugin), this typically indicates corruption in MySQL's system database. The error chain you're seeing suggests either:

  • Critical system tables were deleted/moved
  • The data directory permissions are incorrect
  • Port conflicts preventing initialization

1. Verify Port Availability

Before addressing the missing tables, ensure no port conflicts exist:

netstat -ano | findstr 3306
taskkill /F /PID [PID_from_above]

2. Reinitialize System Tables

Stop any MySQL-related services, then navigate to MySQL's bin directory:

mysqld --initialize-insecure --user=mysql
mysqld --install
net start mysql

3. Post-Initialization Steps

After successful initialization, secure your installation:

mysql_secure_installation
mysql_upgrade -u root -p

If initialization fails, manually recreate the system database:

  1. Backup your existing data directory
  2. Delete contents of the data directory (except any important databases)
  3. Copy the default system tables from a fresh MySQL installation
# Example for MySQL 5.5 on Windows
xcopy "C:\Program Files\MySQL\MySQL Server 5.5\data\mysql" "C:\ProgramData\MySQL\MySQL Server 5.5\data\mysql" /E /I
  • Regularly backup your mysql system database
  • Use mysqlcheck --all-databases --repair periodically
  • Consider running MySQL as a limited user rather than SYSTEM

If issues persist, enable verbose logging:

mysqld --console --log-error-verbosity=3

Check for file permission issues with:

icacls "C:\ProgramData\MySQL\MySQL Server 5.5\data"