MySQL Error: “Can’t open and lock privilege tables: Table ‘mysql.user’ doesn’t exist” – Solutions for Running Multiple Instances


2 views

When attempting to run multiple MySQL instances on Windows, particularly when setting up a new instance alongside an existing one, you might encounter this critical error indicating missing system tables. The error typically manifests during service startup with messages like:

2015-12-16T20:59:53.644445Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2015-12-16T20:59:53.628845Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it

For proper multi-instance MySQL setup on Windows, these elements must be carefully configured:

[mysqld] 
basedir="C:/mysql-5.7.9"
datadir="C:/mysql-5.7.9/data" 
port=3307
socket=mysql579
server-id=2

Here's how to properly initialize a new MySQL instance:

  1. Stop any existing services:
    net stop mysql579
  2. Initialize data directory:
    mysqld --initialize-insecure --basedir="C:/mysql-5.7.9" --datadir="C:/mysql-5.7.9/data"
  3. Start the service:
    net start mysql579
  4. Secure the installation:
    mysql_secure_installation --socket=mysql579 --port=3307
  • Verify directory permissions: The MySQL service account needs full control over both basedir and datadir
  • Check for conflicting my.ini files in Windows directories
  • Examine the error log file (typically in datadir) for detailed startup messages

For production environments, consider adding these parameters to your my.cnf:

[mysqld]
# Multi-instance specific settings
skip-name-resolve
explicit_defaults_for_timestamp=1
secure-file-priv="C:/mysql-5.7.9/tmp"

# Memory settings
innodb_buffer_pool_size=256M
key_buffer_size=64M

When attempting to run a second MySQL instance (v5.7.9) alongside an existing installation on Windows 7, the server fails to start with critical errors about missing system tables, particularly the privilege tables:

2015-12-16T20:59:53.644445Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2015-12-16T20:59:53.628845Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it

The user has:

  • A working MySQL instance running on default port 3306
  • Attempting to install MySQL 5.7.9 on port 3307 with custom datadir
  • Created a proper my.cnf configuration file
  • Successfully registered the Windows service

The my.cnf appears correctly structured:

[client] 
port            = 3307 
socket          = mysql579

[mysqld] 
basedir="C:/mysql-5.7.9"
tmpdir="C:/mysql-5.7.9/tmp" 
datadir="C:/mysql-7.5.9/data" 

port            = 3307 
socket          = mysql579

The fundamental issue is that while the configuration specifies a datadir, MySQL requires explicit initialization of system databases for new installations. For MySQL 5.7+, you must:

mysqld --initialize-insecure --user=mysql --basedir=C:/mysql-5.7.9 --datadir=C:/mysql-5.7.9/data

Alternatively, for secure installation with random root password:

mysqld --initialize --user=mysql --basedir=C:/mysql-5.7.9 --datadir=C:/mysql-5.7.9/data

Here's the proper workflow for parallel MySQL installations:

# 1. Create data directory
mkdir C:\mysql-5.7.9\data

# 2. Initialize data directory (as Administrator)
cd C:\mysql-5.7.9\bin
mysqld --initialize-insecure --user=mysql --basedir=C:/mysql-5.7.9 --datadir=C:/mysql-5.7.9/data

# 3. Install service
mysqld --install mysql579 --defaults-file="C:\mysql-5.7.9\bin\my.cnf"

# 4. Start service
net start mysql579

After successful initialization and startup:

# Connect to the new instance (no password due to --initialize-insecure)
mysql -u root -P 3307 --socket=mysql579

# Set root password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

# Run mysql_upgrade if needed
mysql_upgrade -u root -P 3307 --socket=mysql579 -p
  • Verify the data directory has proper permissions for the MySQL service account
  • Check error logs in C:\mysql-5.7.9\data\hostname.err for detailed startup issues
  • For production environments, use --initialize instead of --initialize-insecure
  • Double-check all path references in my.cnf use forward slashes or escaped backslashes