locate: can not stat () `/var/lib/mlocate/mlocate.db’: No such file or directory

ERROR : locate: can not stat () `/var/lib/mlocate/mlocate.db’: No such file or directory

 

How to fix the above error ?
 
You might see the above error while trying to search a file/directory on your linux server using locate command. Error show that “mlocate.db” file is missing on the server. “mlocate.db” is the database file in which locate command use to keep the location of all files on the server. You will see the above error if you are running locate command for the first time or if it is a newly setup linux server.
You must first run “updatedb” command on the server so that locate will store all the file location in mlocate.db. login to your linux server via SSH as root and just type the command “updatedb” and hit enter.
 

[root@server etc]# locate index.php
locate: can not stat () `/var/lib/mlocate/mlocate.db’: No such file or directory
[root@server etc]# updatedb
[root@server etc]#

 

locate can not stat mlocate.db No such file or directory

locate can not stat mlocate.db No such file or directory

You can start searching files using locate command after “updatedb” is completed. Database file “mlocate.db” is automatically created when we ran “updatedb” command. This database file contain details of location of all files on your Linux server. When you search a file locate command will search this database and provides the file location immediately.
 
[root@server etc]# du -sch /var/lib/mlocate/mlocate.db
976K /var/lib/mlocate/mlocate.db