1. 將mysql中的數(shù)據(jù)導(dǎo)入到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數(shù)據(jù)庫(kù)中的一張表谊路,--hive-table tb1是導(dǎo)入到hive中該表的名字躁垛,不需要事先建表渣玲。
2. 將hive中的數(shù)據(jù)導(dǎo)入到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是導(dǎo)入到mysql中表的名字,需要事先建表
3. 將mysql中的數(shù)據(jù)導(dǎo)入到hdfs中
sqoop import --connect jdbc:mysql://localhost:3306/sqoop --direct --username root --password 123456 --table tb1 -m 1
4. 將hdfs中的數(shù)據(jù)導(dǎo)入到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中的數(shù)據(jù)導(dǎo)入到hdfs中,曾報(bào)以下錯(cuò)誤:
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 andinuse on a given connection. Ensure that you have called .close() on any active streaming result sets before attemptingmorequeries.
經(jīng)查詢刃宵,為mysql JDBC驅(qū)動(dòng)bug所致逊脯,我用的是mysql-connector-java-5.1.10-bin.jar版本的级乍,后改為mysql-connector-java-5.1.25-bin.jar版本的就沒(méi)有問(wèn)題了