cd ~/soft
wget
http://mirrors.sohu.com/mysql/MySQL-5.5/MySQL-5.5.46-1.el6.x86_64.rpm-bundle.tar
[root@hadoop04 hive-0.12.0]# cd /root/app/hive-0.12.0
[root@hadoop04 hive-0.12.0]# cd conf
[root@hadoop04 conf]# cp hive-default.xml.template hive-site.xml
[root@hadoop04 conf]# vi hive-site.xml
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop04:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>admin</value>
</property>
</configuration>
[root@hadoop04 conf]# cd ..
[root@hadoop04 hive-0.12.0]# ./bin/hive
unable to instantiate org.apache.hiv.metastore.hivemetastoreclient
就把mysql.jar上傳到hive-0.12.0/lib而且> set global binlog_format='MIXED';
[root@hadoop04 ~]# hadoop fs -ls /
drwxr-xr-x - root supergroup 0 2015-12-19 04:48 /test.sh
drwx------ - root supergroup 0 2015-12-23 04:31 /tmp
drwxr-xr-x - root supergroup 0 2015-12-24 03:05 /user
[root@hadoop04 ~]# hadoop fs -rm -r /user
[root@hadoop05 sbin]# hadoop fs -ls /
drwxr-xr-x - root supergroup 0 2015-12-19 04:48 /test.sh
drwx------ - root supergroup 0 2015-12-23 04:31 /tmp
[root@hadoop04 hive-0.12.0]# ./bin/hive
hive> create table t_order(id int,name string ,money float)
> row format delimited
>fields terminated by ',';
tbls表
columns_v2表
hive> describe t_order
> ;
OK
id int None
name string None
money float None
Time taken: 0.212 seconds, Fetched: 3 row(s)
/root/soft
[root@hadoop04 hive-0.12.0]# cd ~/soft
[root@hadoop04 soft]# vi order.data
1,iphone,6888
2,xiaomi,3999
3,meizhu,2499
4,mate7, 4398
hive> load data local inpath '/root/soft/order.data' into table t_order;
hive> select * from t_order;
OK
1 iphone 6888.0
2 xiaomi 3999.0
3 meizhu 2499.0
4 mate7 4398.0
Time taken: 1.214 seconds, Fetched: 4 row(s)
[root@hadoop04 hive-0.12.0]# hadoop fs -put ~/soft/order.data /order.data2
hive> load data inpath '/order.data2' into table t_order;
Loading data to table default.t_order
Table default.t_order stats: [num_partitions: 0, num_files: 2, num_rows: 0, total_size: 112, raw_data_size: 0]
OK
Time taken: 18.118 seconds
hive> select * from t_order;
OK
1 iphone 6888.0
2 xiaomi 3999.0
3 meizhu 2499.0
4 mate7 4398.0
1 iphone 6888.0
2 xiaomi 3999.0
3 meizhu 2499.0
4 mate7 4398.0
Time taken: 0.728 seconds, Fetched: 8 row(s)
//外部表被drop只清除元數據,表數據不會被刪除
hive> create external table t_order_ex(id int ,name string ,money double)
> row format delimited
> fields terminated by ','
> location '/hive-tmp/order';
OK
Time taken: 0.31 seconds
hive> load data local inpath '/root/soft/order.data' into table t_order_ex;
Copying data from file:/root/soft/order.data
Copying file: file:/root/soft/order.data
Loading data to table default.t_order_ex
Table default.t_order_ex stats: [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 56, raw_data_size: 0]
OK
Time taken: 1.576 seconds
hive>
hive> drop table t_order;
OK
Time taken: 1.639 seconds
hive> select * from t_order_ex;
OK
1 iphone 6888.0
2 xiaomi 3999.0
3 meizhu 2499.0
4 mate7 4398.0
Time taken: 0.178 seconds, Fetched: 4 row(s)
ctaS用於建立臨時表存儲中間結果
create table tab_ip_ctas
as
select id new_id,name new_name,ip new_ip,country new_croutry
from tab_ip_ext
sort by new_id
假如表已經存在了
create table tab_ip_like tab_ip;
insert overwrite table tab_ip_like
select * from tab_ip;
//cluster<相對高級
hive> create table t_order(id int,name string ,money float)
> row format delimited
> fields terminated by ',';
OK
Time taken: 7.125 seconds
hive> load data local inpath '/root/soft/order.data' into table t_order
java