华为平台loader从关系型数据库到hive

使用华为平台loader将数据从mysql或者oracle中导入至hive中,中间是有过渡的,并不是直接将数据导入至hive中,loader导入完成后,数据会在hdfs上,在导出的文件夹下会有n个文件,假设文件夹为/app/test/,那么还需要执行以下语句才能将数据导入至hive库中:

load data inpath '/app/test' into table table_name


注意在loader平台转换步骤中的hive输出中选择好分隔符,字段值中最好不含有此字符。


hive建表语句:

create table table_name

(

column_name string comment '备注'

)

row format serde

'org.apache.hadoop.hive.serde2.OpenCSVSerde'

with 

SERDEPROPERTIES

("separatorChar"="~")

STORED AS TEXTFILE

;


1、使用sqoop将数据从oracle导入到hive中命令:

    sqoop import --connect 'jdbc:oracle:thin://@192.168.132.123:1521/test' --username bobo --password boge --table table_name -hive-import --hive-database db_name --hive-table table_name -m 1


2、使用sqoop将数据从mysql导入到hive中命令:

    sqoop import --connect 'jdbc:mysql://192.168.12.123:3306/db' --username bobo --password boge --table table_name -hive-import --hive-database db_name --hive-table table_name -m 1


3、使用sqoop从hive导入到mysql:

    sqoop export --connect jdbc:mysql://192.168.174.123:3306/db --username bobo --password boge --table table_name --hcatalog-database db_name --hcatalog-table table_name


4、从mysql导出数据到csv文件:

    select * from table_name into outfile '/app/test.csv' fields terminated by ',' lines terminated by '\r\n';


5、将csv文件导入hive:

    load data local inpath '/app/test.csv' into table table_name;

    




猜你喜欢

转载自blog.csdn.net/MyHeartIsYours/article/details/80190822
今日推荐