1.安装hive中碰到的错误
java.io.IOException: Failed on local exception: java.io.IOException: Connection reset by peer; Host Details : local host is: "master01/192.168.2.6"; destination host is: "localhost":9000;
编辑hadoop的etc/hadoop/core-site.xml文件
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost</value>
</property>
......
</configuration>去掉原先带有的9000端口,再格式化namenode
hdfs namenode -format
接着就发生了其它错误
java.net.ConnectException: Call From master01/192.168.2.6 to localhost:8020 failed on connection exception: java.net.ConnectException: 拒绝连接; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
还发现hdfs的命令(hdfs dfs -ls /)也都报了同样的错误,只好重启当前的hadoop组件,之后再执行命令,恢复正常
2.hive命令
启动服务:
hive --service hiveserver2
进入shell界面:
beeline -u jdbc:hive2://localhost:10000
其他命令可以输入help命令查询
sql语法大致和mysql相同,分页sql如下,不支持指定从哪一行开始:
select * from score limit 20;
3.java代码
hive的Server版本不同,驱动类和url不同,误用会报错
进程参数中包含:
org.apache.hadoop.hive.service.HiveServer
连接创建代码:
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
String url = "jdbc:hive://" + ip + ":" + port + "/" + database;
Connection connection = DriverManager.getConnection(url, username, password);
进程参数中包含:
org.apache.hive.service.server.HiveServer2
连接创建代码:
Class.forName("org.apache.hive.jdbc.HiveDriver");
String url = "jdbc:hive2://" + ip + ":" + port + "/" + database;
Connection connection = DriverManager.getConnection(url, username, password);
关于数据结构用到的sql:
show databases;
show tables;
desc table_name;