DoliWAMP - MySQL5.0.45 - [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: 'host' (errno: 2)

Preface
This is an issue I encountered when I was attempting to install an alternative copy of DoliWAMP, onto the same computer, into a different installation directory, for testing purposes; with the intention of later going back to the original installation.
A backup of the original installation of DoliWAMP was made (copied installation folder to “Dolibarr - Copy”) and then DoliWAMP was uninstalled, so an alternative DoliWAMP installation could be completed.
I think this issue may have come about following the original DoliWAMP folder being copied over the alternative installation folder, which updated the apache and mysql configuration files to point to the original installation location, which when the apache and mysql services were launched, may have resulted in the issue of tables being corrupted or files being deleted.

I’m documenting this error and partial solution I found, because it’s an obscure error on an outdated version of MySQL. I hope someone with more knowledge in the area can explain why the REPAIR TABLE command failed to work, because others encountering this error may not have a full backup copy of the installation folder at their disposal.


Issue
Doliwampmysqld (mysqld-nt.exe) service: fails to start
mysql.log:
[ERROR] Fatal error: Can’t open and lock privilege tables: Can’t find file: ‘host’ (errno: 2)
or
[ERROR] Fatal error: Can’t open and lock privilege tables: Can’t find file: ‘user’ (errno: 2)
or
[ERROR] Fatal error: Can’t open and lock privilege tables: Can’t find file: ‘db’ (errno: 2)


Unsuccessful repair
I ported the referenced guide for use with Windows, and attempted a repair of the host table, as follows:

Ensure the doliwampmysqld service is stopped
As this issue relates to a Fatal Error, which would result in mysqld-nt.exe terminating after launch, the service encountering this error should already not be running.
If it is still running (mysqld-nt.exe is in Task Manager), consideration should be given as to why the service is running, and whether this guide is appropriate for your circumstances.

Locate the latest error in the logs

notepad C:\dolibarr\logs\mysql.log

Run mysqld from administrator command prompt

cd C:\dolibarr\bin\mysql\mysql5.0.45\

.\bin\mysqld-nt.exe --skip-grant-tables

Run mysql table repair from separate standard-privilege command prompt
In the commands below, replace table-name with the name of the file specified by the error message in the MySQL log

cd C:\dolibarr\bin\mysql\mysql5.0.45

.\bin\mysql.exe

mysql> use mysql
mysql> repair table _table-name_ use_frm;
+------------+--------+----------+------------------------------------+
|__ Table ___|__ Op __| Msg_type |_____________ Msg_text _____________|
| mysql.host | repair |_ error! _| Can't find file: 'host' (errno: 2) |
+------------+--------+----------+------------------------------------+
1 row in set (0.04 sec)

If anyone has a solution to this error please detail it below

Ref: percona - MySQL Fatal error: Can't open and lock privilege tables: Incorrect file format 'user' - Stack Overflow - percona - MySQL Fatal error: Can't open and lock privilege tables: Incorrect file format 'user' - Stack Overflow


Partial solution
This solution relies upon a previous complete backup copy of the DoliWAMP installation folder being available

Launch the doliwampmysqld service (administrator command prompt)

sc start doliwampmysqld
sc query doliwampmysqld

Locate the error in the logs
If after starting the doliwampmysqld service, the reported state of the service is ‘1 STOPPED’, then find the latest error in the mysql.log

notepad C:\dolibarr\logs\mysql.log

Compare between the live and backup DoliWAMP ‘bin\mysql\data\mysql’ folders

  1. Compare the presence of files with name of that referred to in the latest error message in the MySQL log.
    e.g. live has 1 host file with the extension .frm, while backup has 3 files with the extensions .frm, .MYD and .MYI

  2. Copy any missing files with the name referred to by the error message in the MySQL log.

Repair the table which is referred to by the error message in the MySQL log

  1. Perform the actions detailed above in the Unsuccessful repair section under the headings Run mysqld from administrator command prompt and Run mysql table repair from separate standard-privilege command prompt

  2. The repair table command should return: OK

mysql> repair table _table-name_ use_frm;
+------------+--------+----------+----------+
|__ Table __ |__ Op __| Msg_type | Msg_text |
+------------+--------+----------+----------+
| mysql.host | repair |_ status _|___ OK ___|
+------------+--------+----------+----------+
1 row in set (0.11 sec)

Shutdown mysqld-nt.exe

  1. Shutdown mysqld-nt using mysqladmin from a separate standard-privilege command prompt

C:\dolibarr\bin\mysql\mysql5.0.45\bin\mysqladmin.exe shutdown

Rinse and repeat
Perform stages 1-5, until the reported state of the doliwampmysqld service is ‘4 RUNNING’; then review the mysql.log for any other errors or the following entries:

InnoDB: Started; log sequence number 0 10297929
[Note] doliwampmysqld-test: ready for connections.
Version: ‘5.0.45-community-nt’ socket: ‘’ port: 3306 MySQL Community Edition (GPL)

1 Like