sqoop簡單使用

suifeng2316發表於2015-04-16
[hadoop@dbsrv1 bin]$ ./sqoop help
Available commands:
  codegen            Generate code to interact with database records
  create-hive-table  Import a table definition into Hive
  eval               Evaluate a SQL statement and display the results
  export             Export an HDFS directory to a database table
  help               List available commands
  import             Import a table from a database to HDFS
  import-all-tables  Import tables from a database to HDFS
  job                Work with saved jobs
  list-databases     List available databases on a server
  list-tables        List available tables in a database
  merge              Merge results of incremental imports
  metastore          Run a standalone Sqoop metastore
  version            Display version information
加入mysql的jdbc驅動
[hadoop@dbsrv1 lib]$ pwd
/usr/local/sqoop1.4.5/lib
1)列出mysql資料庫中的所有資料庫
[hadoop@dbsrv1 bin]$ ./sqoop list-databases --connect jdbc:mysql://localhost:3306/ --username root --password aaa#123
2)列出mysql資料庫中的表
[hadoop@dbsrv1 bin]$ ./sqoop list-tables   --connect jdbc:mysql://localhost:3306/jiradb --username root --password aaa#123
3)把資料從mysql匯入到hdfs中
[hadoop@dbsrv1 bin]$ ./sqoop  import --table avatar --fields-terminated-by '==' -m 1 --connect jdbc:mysql://localhost:3306/jiradb --username root --password aaa#123

sqoop操作oracle
[hadoop@dbsrv1 lib]$ sqoop import --table t_guide --fields-terminated-by '\t' -m 1 --connect jdbc:oracle:thin:@192.168.1.153:1521:orcl --username test --password=test#123 
15/04/16 16:33:58 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5
15/04/16 16:33:59 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
15/04/16 16:33:59 INFO oracle.OraOopManagerFactory: Data Connector for Oracle and Hadoop is disabled.
15/04/16 16:33:59 INFO manager.SqlManager: Using default fetchSize of 1000
15/04/16 16:33:59 INFO tool.CodeGenTool: Beginning code generation
15/04/16 16:34:00 INFO manager.OracleManager: Time zone has been set to GMT
15/04/16 16:34:00 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM t_guide t WHERE 1=0
15/04/16 16:34:02 ERROR tool.ImportTool: Imported Failed: There is no column found in the target table t_guide. Please ensure that your table name is correct.

將表名改成大寫就ok了
[hadoop@dbsrv1 lib]$ sqoop import --table T_GUIDE --fields-terminated-by '\t' -m 1 --connect jdbc:oracle:thin:@192.168.1.153:1521:orcl --username test --password=test#123 
記錄:將一個oracle表 記錄數:260w,物理大小4G,從oracle到hdfs用時4m



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23073818/viewspace-1580429/,如需轉載,請註明出處,否則將追究法律責任。