1.从文件中加载数据
建表语句:
hive> CREATE TABLE IF NOT EXISTS `test.test7`(
> `user_id` int,
> `name` string,
> `address` string)
> row format delimited
> fields terminated by ',';
OK
Time taken: 0.055 seconds
注意:建表的分隔符必须与文件中数据的分隔符一致,不然数据无法分割
从本地加载数据:
(1)load方式
hive> load data local inpath '/home/hadoop/data/test7.txt' into table test.test7;
Loading data to table test.test7
OK
Time taken: 0.463 seconds
(2)put方式
hive> dfs -put /home/hadoop/data/test7.txt /usr/hive/warehouse/test.db/test7/;
从hdfs加载数据:
hive> load data inpath 'test/data/test7.txt' into table test.test7;
Loading data to table test.test7
OK
Time taken: 0.392 seconds
2.通过其他表加载数据
hive> insert into table test.test7
> select
> id,
> name,
> address
> from test.test2;
3.通过as方式建表时加载数据
注意:只能以as方式加载数据,如其他有分区字段,分区字段只以字段形式保留
hive> create table test.test7 as
> select
> user_id,
> name,
> address
> from test.test2;
4.手动插入数据(同方式3)
hive> insert into table test.test7
> select 1 as user_id,'xiaoming' as name,'shanghai' as address
> union all
> select 2 as user_id,'xiaolan' as name,'beijing' as address;
注意:
hive的语法不同于mysql,不支持insert into table values()