hive环境搭建相比较其他组件而言,很简单
1安装mysql
(如果机器自带可以省略该步骤)
[root@localhost hive-x.x.x]# yum install mysql mysql-server mysql-devel
设置mysql配置文件/etc/my.cnf中加入default-character-set=latin1
启动mysql
[root@localhost hive-x.x.x]# /etc/init.d/mysqld start
开机启动
[root@localhost hive-x.x.x]# chkconfig --add mysqld
[root@localhost hive-x.x.x]# chkconfig --level 2345 mysqld on
设置mysql root密码
[root@localhost hive-x.x.x]# mysqladmin -uroot password 111111
创建hive数据库
mysql> create database hive;
2 hive数据库mysql相关设置
设置hive-site.xml
[root@localhost hive-x.x.x]# vim conf/hive-site.xml
javax.jdo.option.ConnectionURL
jdbc:mysql://localhost:3306/hive
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName
root
javax.jdo.option.ConnectionPassword
111111
datanucleus.schema.autoCreateAll
true
hive.metastore.warehouse.dir
/user/hive/warehouse
hive.exec.scratchdir
/tmp/hive
hive.scratch.dir.permission
700
相关共享文件夹创建
[hdfs@localhost hadoop-2.6.0]$ ./bin/hadoop fs -mkdir /tmp
[hdfs@localhost hadoop-2.6.0]$ ./bin/hadoop fs -chmod a+w /tmp
[hdfs@localhost hadoop-2.6.0]$ ./bin/hadoop fs -mkdir -p /user/hive/warehouse
[hdfs@localhost hadoop-2.6.0]$ ./bin/hadoop fs -chmod a+w /user/hive/warehouse
[hdfs@localhost hadoop-2.6.0]$ ./bin/hadoop fs -chown hive: /user/hive
拷贝数据库驱动mysql-connector-java-xxx-bin.jar到hive的lib下面
[root@localhost hive-x.x.x]# mv mysql-connector-java.jar lib/
设置hive日志
[root@localhost hive-x.x.x]# cp conf/hive-log4j2.properties.template conf/hive-log4j2.properties
初始化好数据
执行初始化命令:schematool -dbType mysql -initSchema
查看初始化后的信息: schematool -dbType mysql -info
详见:https://cwiki.apache.org/confluence/display/Hive/Hive+Schema+Tool
3启动hive
[hive@localhost hive-x.x.x]$ ./bin/hive
hive> show tables;
OK
Time taken: 0.766 seconds
hive> create table dummy (value string);
OK
Time taken: 0.091 seconds
hive> show tables;
OK
dummy
Time taken: 0.751 seconds, Fetched: 1 row(s)
ps:创建数据文件dummy.txt,echo "aaa" > /tmp/dummy.txt
hive> load data local inpath '/tmp/dummy.txt' overwrite into table dummy;
Loading data to table default.dummy
OK
Time taken: 0.993 seconds
hive> select * from dummy;
OK
aaa
Time taken: 0.732 seconds, Fetched: 1 row(s)
[徐银浩PC1]mysql版本要求?