'MinGW pacman -Sys Unable to lock database

To start Code and Compile C++, must install a compiler. For my case, it is MSYS2 through which MinGW is available. According to the installation guild mentioned on the website, I installed the software without any errors. Now I was supposed to update the package database and base packages by entering pacman -Sys but it has shown an error error: failed to synchronize all databases (unable to lock database)

After searching online for a solution I found that deleting/removing the db.lck will work, for that, I used this command rm /var/lib/pacman/db.lck but it showed another error. Right now there is no solution to this on the internet. I've also pasted the terminal output of MSYS2 MSYS for refernce.

$ pacman -Sys
:: Synchronizing package databases...
error: failed to synchronize all databases (unable to lock database)

VIRAT@DESKTOP-97BS0AB MSYS ~
$ rm /var/lib/pacman/db.lck
rm: cannot remove '/var/lib/pacman/db.lck': No such file or directory

VIRAT@DESKTOP-97BS0AB MSYS ~
$ pacman -S --needed base-devel mingw-w64-x86_64-toolchain
error: failed to init transaction (unable to lock database)
error: could not lock database: Permission denied

VIRAT@DESKTOP-97BS0AB MSYS ~
$ pacman -Su
error: failed to init transaction (unable to lock database)
error: could not lock database: Permission denied

VIRAT@DESKTOP-97BS0AB MSYS ~
$


Solution 1:[1]

Try to run MSYS app under administrator privilege... worked for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pedro