sqoop数据导出导入命令

1. 将mysql中的数据导入到hive中

sqoop import --connect jdbc:mysql://localhost:3306/sqoop --direct --username root --password 123456 --table tb1 --hive-table tb1 --hive-import -m 1

其中--table tb1是mysql sqoop数据库中的一张表,--hive-table tb1是导入到hive中该表的名字,不需要事先建表。

2. 将hive中的数据导入到mysql中

sqoop export --connect jdbc:mysql:localhost:3306/sqoop --username root --password 123456 --direct --table t4 --export-dir /user/hive/warehouse/tb1/part-m-00000 --input-fields-terminated-by '\001'

--table t4是导入到mysql中表的名字,需要事先建表

3. 将mysql中的数据导入到hdfs中

sqoop import --connect jdbc:mysql:localhost:3306/sqoop --direct --username root --password 123456 --table tb1 -m 1

4. 将hdfs中的数据导入到mysql中

sqoop export --connect jdbc:mysql:localhost:3306/sqoop --direct --table tb1 --username root --password 123456 --export-dir hdfs:localhost:9000/user/hadoop/tb1/part-m-00000 -m 1

同样需先在mysql中建立tb1表

在用sqoop将mysql中的数据导入到hdfs中,曾报以下错误:

java.sql.SQLException: Streaming result set com.mysql.jdbc.RowDataDynamic@54b0a583 is still active. No statements may be issued when any streaming result sets are open and in use on a given connection. Ensure that you have called .close() on any active streaming result sets before attempting more queries.

经查询,为mysql JDBC驱动bug所致,我用的是mysql-connector-java-5.1.10-bin.jar版本的,后改为mysql-connector-java-5.1.25-bin.jar版本的就没有问题了

 

相关文章

文章浏览阅读5.3k次,点赞10次,收藏39次。本章详细写了mysq...
文章浏览阅读1.8k次,点赞50次,收藏31次。本篇文章讲解Spar...
文章浏览阅读7.8k次,点赞9次,收藏34次。ES查询常用语法目录...
文章浏览阅读928次,点赞27次,收藏18次。
文章浏览阅读1.1k次,点赞24次,收藏24次。作用描述分布式协...
文章浏览阅读1.5k次,点赞26次,收藏29次。为贯彻执行集团数...