hive (一)
1、配置 hive-site.xml
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 3 <configuration> 4 <property> 5 <name>javax.jdo.option.ConnectionURL</name> 6 <value>jdbc:mysql://master/hive?createDatabaseIfNotExist=true</value> 7 </property> 8 <property> 9 <name>javax.jdo.option.ConnectionDriverName</name> 10 <value>com.mysql.jdbc.Driver</value> 11 </property> 12 <property> 13 <name>javax.jdo.option.ConnectionUserName</name> 14 <value>root</value> 15 </property> 16 <property> 17 <name>javax.jdo.option.ConnectionPassword</name> 18 <value>MyNewPass1!</value> 19 </property> 20 <property> 21 <name>hive.metastore.schema.verification</name> 22 <value>false</value> 23 <description> 24 Enforce metastore schema version consistency. 25 True: Verify that version information stored in metastore matches with one from Hive jars. Also disable automatic 26 schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures 27 proper metastore schema migration. (Default) 28 False: Warn if the version information stored in metastore doesn't match with one from in Hive jars. 29 </description> 30 </property> 31 </configuration>
2、初始化
bin/schematool -initSchema -dbType mysql
3、
4、
4、开启开启 metastore和hiveserver2
hive --service metastore &
hive --service hiveserver2 &
可以通过命令netstat -ntulp |grep 10000
可以看到结果
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 27799/java
5、hive jdbc
1 public static void main(String[] args) throws Exception { 2 Class.forName("org.apache.hive.jdbc.HiveDriver"); 3 // default为数据库名 4 Connection con = DriverManager.getConnection("jdbc:hive2://master:10000/db_hive_test"); 5 Statement stmt = con.createStatement(); 6 String querySQL = "SELECT * FROM student"; 7 8 ResultSet res = stmt.executeQuery(querySQL); 9 10 while (res.next()) { 11 System.out.println(res.getString(1)+","+res.getString(2)); 12 } 13 14 }
hive安装:参考https://www.cnblogs.com/hmy-blog/p/6506417.html