If you get the below error when trying out any queries in hive,

then the problem might be because the user you logged in as (cloudera or find user by typing ‘whoami’) does not have write access to the derby metastore database directory used by Hive. The Hive metastore stores the metadata for a table and provides this metadata to the Hive compiler for converting SQL commands to MapReduce jobs.

So, go to the metastore/metastore_db and verify if your user id has permissions by doing an ls -lrt. If your userid does not have permissions,  you should grant write permissions to it. Below are the commands :

Step 1: search the location of metastore_db in hive-site.xml

cd /usr/lib/hive/conf

grep metastore_db hive-site.xml


Now go to your the directory where your metastore_db is present. (Mine is at /var/lib/hive/metastore)

cd /var/lib/hive/metastore/metastore_db

sudo chmod a+rwx . recursive

sudo \rm *.lck


Now you can enter hive shell and the queries will not give any exception