Is there any way to identify which database the user is using while using the command line interface ?
To know which database user in
hive> set hive.cli.print.current.db=true
or start hive with
hive --hiveconf hive.cli.print.current.db=true
then the prompt will display
hive (db_name)>
There are two ways to know the current database. One temporary in cli and second one is persistently.
1) in CLI just enter this command: set hive.cli.print.current.db=true;
2) In hive-site.xml paste this code:
<property> <name>hive.cli.print.current.db</name> <value>true</value> </property>
In second scenario, you can automatically display the Hive dabatabase name when you open terminal.
Set hive.cli.print.current.db=true; sets the property in current hive session only. If one is out of the session the setting would be reset to default(false).
To be able to see the database name consistently accross sessions and users, root user can create .hiverc file in /etc/hive/conf with required parameter values. In this case add set hive.cli.print.current.db=true; These settings are now applied across all the users logging into hive CLI.
if the user is not root user, create .hiverc file in home directory /home/<>.The settings would be effective across all the hive sessions for the user.
A simple way (if there's table in the db):
desc extended {table_name};
From the output, dbName is what you are looking for.
while updating the conf property set hive.cli.print.current.db=true will show the current DB for the current session..
updating the .hiverc file with the above property will keep showing the current db for all the sessions.
1)Permanent solution:
Change this property in hive-site.xml file under HIVE_HOME/conf folder
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
<description>Whether to include the current database in the Hive prompt.
</description>
</property>
2)Temporary solution:
go to hive prompt enter this
hive> set hive.cli.print.current.db=True
For keeping the database name persistent in the hive cli.
Add set hive.cli.print.current.db=true; to .hiverc file.
If the .hiverc is not present under hive/conf then create one.
It wont reflect if one tries to add in hive-site.xml
© 2022 - 2024 — McMap. All rights reserved.