Sqoop导入导出——hive<=>mysql

Mysql通过sqoop导入到hdfs,hive建表导入hdfs路径的数据,hive通过sqoop导出到mysql。

导出:

sqoop 推送mysql数据到hive中:

sqoop export 
--connect "jdbc:mysql://localhost:3306/hoteldata?useUnicode=true&characterEncoding=utf-8" 
--username root 
--password root 
--table rawdata 
--input-fields-terminated-by "," -
--export-dir "/user/hive/warehouse/hoteldata.db/rawdata"

将hive的数据导出到mysql:是通过hdfs中的路径导入到mysql中。

导入:

如果mysql中的表没有主键,需要指定–split-by

sqoop  import 
--connect "jdbc:mysql://192.168.3.25:3306/jd_hotel" 
--username root 
--password 123456 
--table tbl_hotel
 --target-dir /h3c/s3/jd_hotel  
 --split-by id

导出分隔符:
–fields-terminated-by ‘|’
–lines-terminated-by '\n’

解析数字时遇到了None,在pyspark里导出来的空值可能是被替换成None.

–input-null-string ‘None’ --input-null-non-string ‘None’ 通过这个参数指定None作为空的值
–split-by id 划分id自动分成n个map来进行数据导入

Guess you like

Origin blog.csdn.net/white_mvlog/article/details/115689731