hive 原理与安装

hive原理与安装

hive是把类似SQL的语名变成相关的mapreduce任务进行计算得到结果,对于结构化数据,可以不用写mapreduce程序就可以进行大数统计分析.

hive使用mysql、Derby作为hive元数据的存储

将数据文件放入hive建立的表目录中,hive就可以使用SQL语句进行查询了(

如:hadoopfs-put/home/hadoop/testFile/t_boy.data/user/hive/warehouse/test001.db/t_boy,,其中t_boy是建立的一张hive表,在test001.db(数据库)中)

t_boy.data数据:

1huang1832

2yong1934

3xing2036

4ming2138

5ling2540

//安装

https://blog.csdn.net/t1dmzks/article/details/72026876(安装)

https://blog.csdn.net/just4you/article/details/79981202(安装)

https://www.yiibai.com/hive/hive_installation.html(hive教程)

cd/home/hadoop/

tar-zxvfapache-hive-1.2.2-bin.tar.gz-C/home/hadoop/

设置环境变量

vim/etc/proflie

exportHIVE_HOME=ome/hadoop/apache-hive-1.2.2-bin

exportPATH=$PATH:$HIVE_HOME/bin

//配置

cd$HIVE_HOME/conf/

cphive-default.xml.templatehive-site.xml

cphive-env.sh.templatehive-env.sh

cphive-exec-log4j.properties.templatehive-exec-log4j.properties

cphive-log4j.properties.templatehive-log4j.properties

//hive-site.xml

<configuration>

<property>

<name>javax.jdo.option.ConnectionURL</name>

<!--mysql默认端口3306-->

<value>jdbc:mysql://ubuntuHadoop:3306/hive</value>

</property>

<property>

<name>javax.jdo.option.ConnectionDriverName</name>

<value>com.mysql.jdbc.Driver</value>

</property>

<property>

<name>javax.jdo.option.ConnectionUserName</name>

<!--创建的hive用户-->

<value>root</value>

</property>

<property>

<name>javax.jdo.option.ConnectionPassword</name>

<!--创建hive用户时设置的密码-->

<value>123456</value>

</property>

</configuration>

//运行

./hive

//出错就把

[ERROR]Terminalinitializationfailed;fallingbacktounsupported

java.lang.IncompatibleClassChangeError:Foundclassjline.Terminal,butinterfacewasexpected

//处理

/home/hadoop/hadoop-2.6.5/share/hadoop/yarn/jline-0.9.94.jar删除,

放入放hive目录中的lib里的jlineXXXX.jar

//测试

showdatabases;

createdatabasetest001;

usetest001;

在mysql中先设置字符集,否则会报message:FordirectMetaStoreDBconnections,wedon'tsupportretriesattheclientlevel.

mysql>alterdatabasehivecharactersetlatin1;

createtablet_boy(idint,nmaestring,ageint,sizestring);

showtables;

createtablet_boy(idint,nmaestring,ageint,sizestring)

rowformatdelimited

fieldsterminatedby"\t";

createtablet_baby(idint,nmaestring,ageint,sizestring)

rowformatdelimited

fieldsterminatedby"\t";

hadoopfs-put/home/hadoop/testFile/t_boy.data/user/hive/warehouse/test001.db/t_boy

usetest001;

select*fromt_boy;

select*fromt_boywhereage<20;

selectcount(*)fromt_boy;//时间会长一点,因为要启动mapREDUce进行计算

相关推荐