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

**URL:** <https://www.dolibarr.org/forum/t/doliwamp-mysql5-0-45-error-fatal-error-cant-open-and-lock-privilege-tables-cant-find-file-host-errno-2/18137>\
**Category:** Maintaining my Dolibarr\
**Tags:** v10, Issue, Windows\
**Created:** [November 24, 2019, 7:55pm UTC](https://www.dolibarr.org/forum/t/doliwamp-mysql5-0-45-error-fatal-error-cant-open-and-lock-privilege-tables-cant-find-file-host-errno-2/18137 "2019-11-24T19:55:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattmill30](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mattmill30](https://www.dolibarr.org/forum/u/mattmill30)\
**Post date:** [November 24, 2019, 7:55pm UTC](https://www.dolibarr.org/forum/t/doliwamp-mysql5-0-45-error-fatal-error-cant-open-and-lock-privilege-tables-cant-find-file-host-errno-2/18137/1 "2019-11-24T19:55:03Z")

</div>

**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](https://stackoverflow.com/a/31695983) - [percona - MySQL Fatal error: Can't open and lock privilege tables: Incorrect file format 'user' - Stack Overflow](https://stackoverflow.com/questions/28521530/mysql-fatal-error-cant-open-and-lock-privilege-tables-incorrect-file-format/31695983#31695983)

` `  
**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)
