how to get database username and password in hive

时间秒杀一切 提交于 2019-12-23 09:58:02

问题


Am writing jdbc program to connect hive database. I want the username and password to give it in the connection url.

I don't know how to get the username and password using hive QL. Can anybody help me out??

Exception in thread "main" java.sql.SQLNonTransientConnectionException: [DataDirect][Hive JDBC Driver]A value was not specified for a required property: PASSWORD
    at com.ddtek.jdbc.hivebase.ddcp.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.ddcp.a(Unknown Source)
    at com.ddtek.jdbc.hivebase.ddco.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.ddco.a(Unknown Source)
    at com.ddtek.jdbc.hive.HiveImplConnection.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.k(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.a(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at hivejdbcconnection.HiveJdbcConnection.main(HiveJdbcConnection.java:33)
Java Result: 1

回答1:


To get hive username and password, go to hive-site.xml and search for javax.jdo.option.ConnectionUserName and javax.jdo.option.ConnectionPassword. The values of these properties are your hive username and password respectively.

(Default values are APP and mine for username and password which can be found in hive-default.xml)

In case, if you don't have such property in hive-site.xml. Then add these lines in hive-site.xml:

<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>hiveuser</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>hivepass</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost:3306/hadoop</value>
</property>

Note: I have a database named hadoop in mysql for hive. Thats why the value for javax.jdo.option.ConnectionURL is jdbc:mysql://localhost:3306/hadoop.

After setting or finding your username and password, use it as follows:

Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hiveuser", "hivepass");

Use your hive database name instead of default. Hope it helps!!!!




回答2:


hive default user name is hive

use the below connection string for hiveserver2

"jdbc:hive2://localhost:10000/default", "hive", ""

for hiveserver1 default is empty,hiveserver2 also works with empty username and password.

jdbc:hive://localhost:10000/default

Driver name: org.apache.hadoop.hive.jdbc.HiveDriver

Username and password are empty

read the link Connecting to Hive using Beeline



来源:https://stackoverflow.com/questions/29362166/how-to-get-database-username-and-password-in-hive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!