zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Hive数据的导入

2023-06-13 09:17:16 时间

Hive支持两种方式的数据导入

使用load语句导入数据
使用sqoop导入关系型数据库中的数据
使用load语句导入数据
导入本地的数据文件
load data local inpath '/home/centos/a.txt' into  table  tt;

注意:Hive默认分隔符是: tab键。所以需要在建表的时候,指定分隔符。

导入HDFS上的数据
load data inpath '/home/centos/a.txt' into  table  tt;
使用sqoop导入关系型数据库中的数据
将关系型数据的表结构复制到hive中

sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test --table username --username root --password 123456 --hive-table test

其中 --table username为mysql中的数据库test中的表   --hive-table test 为hive中新建的表名称

##########

从关系数据库导入文件到hive中

sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password mysql-password --table t1 --hive-import

##########

将hive中的表数据导入到mysql中
sqoop export --connect jdbc:mysql://localhost:3306/test --username root --password admin --table uv_info --export-dir /user/hive/warehouse/uv/dt=2011-08-03