Hive-导入数据

将本地文件导入到hive表中

将本地文件导入到hive表中

load data local inpath '/home/data/student01.txt' into table t3;

将某个文件夹下的所有文件导入到hive表中

load data local inpath '/home/data/hive/' into table t3;

将某个文件夹下的所有文件导入到hive表中,并且覆盖原来的数据

load data local inpath '/home/data/hive/' overwrite into table t3;

将HDFS中的文件导入到hive表中

将HDFS中的文件导入到hive表中,用法和前面的类似,只是少了"local"这个单词,例如:

load data inpath '/student02.txt' into table t3;

将数据导入到分区表

load data local inpath '/home/data/data01.txt' into table partition_table partition(gender='M');

操作MySQL数据库中的数据

使用sqoop将mysql数据库导入到hdfs,

sqoop import --connect jdbc:mysql://localhost/lzc --username root --password root --table student --columns 'id,name,password' -m 1 --target-dir '/lzc'

使用sqoop导入mysql数据到hive,默认会存储在default下

sqoop import --hive-import --connect jdbc:mysql://localhost/lzc --username root --password root --table student --columns 'id,name,password' -m 1

用法

--hive-import    数据导入到hive中


--connect jdbc:mysql://localhost/db_name --username root --password root       连接数据库并指定哪个数据库


--table db_name      指定表名


--columns 'column_1,column_2,column_3,...'     获取哪些列


--hive-database hive_database_name     指定hive数据库名字


--create-hive-table     自动创建表


--hive-table hive_table_name     指定hive表名


--hive-overwrite     参数是覆盖数据


-m 1     使用一个MapReduce作业进程


--fields-terminated-by '  '     指定列与列之间的间隔符


--where 'name="lizhencheng"'     条件语句


--target-dir '/lzc'     指定HDFS路径


--query "select * from student where $CONDITIONS" -target-dir '/user/hive/warehouse'     查询,一定要指定HDFS路径


--query "select * from student where  id >= 3 and $CONDITIONS" -target-dir '/user/hive/warehouse'     查询一定要指定HDFS路径


--split-by 参数    数据库表没有主键时,需要指定

where语句

sqoop import --hive-import --connect jdbc:mysql://localhost/lzc --username root --password root  --table student --columns 'id,name,password' --where 'name="lizhencheng"' --hive-table student00 -m 1

查询语句

sqoop import --hive-import --connect jdbc:mysql://localhost/lzc --username root --password root  --query 'select * from student where  $CONDITIONS' --target-dir '/user/hive/warehouse/' -m 1 --hive-table student01
sqoop import --hive-import --connect jdbc:mysql://localhost/lzc --username root --password root  --query 'select * from student where id >= 3 and $CONDITIONS' --target-dir '/user/hive/warehouse/student3' -m 1 --hive-table student03
sqoop import --hive-import --connect jdbc:mysql://localhost/lzc --username root --password root  --query 'select * from student where id >= 3 and name = "lizhencheng" and $CONDITIONS' --target-dir '/user/hive/warehouse/student4' -m 1 --hive-table student04

将HDFS(Hive)中的数据导入到MySQL

sqoop export --connect jdbc:mysql://localhost/lzc --username root --password root  --table person --export-dir /user/hive/warehouse/student/part-m-00000 --columns 'id,name,password' --fields-terminated-by '\t' -m 1

猜你喜欢

转载自blog.csdn.net/lizc_lizc/article/details/82757190