1、执行导入的操作命令:在Sqoop的安装目录下bin目录下执行命令

sqoop import --driver com.mysql.jdbc.Driver --connect jdbc:mysql://数据库主机ip:3306/数据库名?useUnicode=true&characterEncoding=utf-8 --username root --password 密码 --hive-table hive表名 --table 数据库表名称 --hive-import -m 1;

如:

sqoop import --driver com.mysql.jdbc.Driver --connect "jdbc:mysql://192.168.2.73:3306/student?useUnicode=true&characterEncoding=utf-8" --username root --password cecgw --hive-table stu_ttt --table stu --hive-import -m 1;

执行成功:

利用Sqoop从MySQL数据源向Hive中导入数据利用Sqoop从MySQL数据源向Hive中导入数据

2、hive本地文件导入
1)hive建表:
hive>create table tb_emp_info(id int,name string,age int,tel string)ROW FORMAT DELIMITEDFIELDS TERMINATED BY '|'STORED AS TEXTFILE;  

注意分隔符为'|'

2)本地文件导入

先构造数据文件ba.txt

1|name1|25|13188888888888
2|name2|30|13888888888888
3|name3|3|147896221
4|name4|56|899314121
5|name5|12|899314121
6|name6|9|899314121
7|name7|32|899314121
8|name8|42|158964
9|name9|86|899314121
10|name10|45|789541

hive>LOAD DATA LOCAL INPATH '/home/bigdata/ba.txt' INTO TABLE tb_emp_info;
3)查看导入记录

hive>select * from t_evninfo2 limit 10;

利用Sqoop从MySQL数据源向Hive中导入数据

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2022-01-09
  • 2021-10-27
  • 2022-01-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
相关资源
相似解决方案