我在存储在HDFS中的dataset上使用了Pig和Hive进行MapReduce操作。现在,我希望将该输出传输到MySQL表中。
如何将输出传输到MySQL?
发布于 2018-04-28 19:55:00
您可以利用Apache Sqoop从HDFS导出到MySQL。
插图:
这是HDFS中的数据
# hadoop fs -ls /example_hive
/example_hive/file1.csv
# hadoop fs -cat /example_hive/*
1,foo
2,bar
3,ack
4,irk
5,pqrtest 在MySQL 数据库中创建目标表
> create table test.example_mysql(h1 int, h2 varchar(100));使用Sqoop命令.导出(根据环境更新参数-连接、--用户名、--密码)
# sqoop export --connect "jdbc:mysql://localhost/test" --username "root" --password hadoop --table "example_mysql" --export-dir "hdfs:///example_hive" --input-fields-terminated-by ','检查MySQL中的数据
> select * from test.example_mysql;
+------+------+
| h1 | h2 |
+------+------+
| 1 | foo |
| 2 | bar |
| 3 | ack |
| 4 | irk |
| 5 | pqr |
+------+------+https://stackoverflow.com/questions/50080198
复制相似问题