How to identify which database the user is using in hive CLI ?
Asked Answered
W

8

18

Is there any way to identify which database the user is using while using the command line interface ?

Whitesmith answered 1/8, 2013 at 6:14 Comment(0)
W
32

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)>
Whitesmith answered 1/8, 2013 at 6:14 Comment(2)
how about in beeline?Epineurium
How can do this for beeline?Disannul
V
5

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.

Vestibule answered 8/5, 2015 at 12:25 Comment(0)
O
5

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.

Ossian answered 17/9, 2016 at 18:32 Comment(0)
A
4

A simple way (if there's table in the db):

desc extended {table_name};

From the output, dbName is what you are looking for.

Ashly answered 14/3, 2017 at 2:13 Comment(0)
R
2

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.

Rael answered 2/8, 2013 at 12:39 Comment(0)
H
2
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
Helicoid answered 10/7, 2017 at 11:31 Comment(0)
L
1

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

Lauren answered 12/10, 2015 at 14:0 Comment(0)
B
0

For beeline use this command: select current_database();

Barclay answered 7/2 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.