使用sqoop导出SqlServer数据库具体表数据到Hive数据库:
sqoop import语句:
按表中字段筛选 | $SQOOP_HOME/bin/sqoop import \ --connect 'jdbc:sqlserver://168.16.8.168:5419;database=database_name' \ --username 'user' \ --password '12345678' \ --table dt_tablename \ --columns 'id,createtime,name,mobile' \ --null-string '\\N' \ ##没有这个,导入的数据值都为NULL --hive-import \ --hive-database hiveDatabase \ --hive-table tablename_h \ --fields-terminated-by '\001' \ --hive-drop-import-delims \ --incremental append \ --check-column id \ --last-value 1 \ --m 2 |
自主写sql | /bin/sqoop import \ 注意,用--query When importing a free-form query, you must specify a destination directory with 导入自由格式查询时,必须使用--target dir指定目标目录。 |
sqoop参数说明:
--columns <col,col,col…> | Columns to export to table |
-e,--query <statement> | Sqoop can also import the result set of an arbitrary SQL query. Sqoop还可以导入任意SQL查询的结果集。可以使用--query参数指定SQL语句,而不是使用--table、--columns和--where参数。 注意不和 |
--create-hive-table | If set, then the job will fail if the target hive table exits. By default this property is false. 如果设置,则如果目标配置单元表退出,则作业将失败。默认情况下,此属性为false。 |
--hive-overwrite | Overwrite existing data in the Hive table. 覆盖配置单元表中的现有数据 |
--hive-drop-import-delims | Drops \n, \r, and \01 from string fields when importing to Hive. 导入配置单元时,从字符串字段中删除\n、\r和\01。 |
--incremental | Specifies how Sqoop determines which rows are new. Legal values for mode include append and lastmodified. 指定Sqoop如何确定哪些行是新的。合法值包括mode,append和lastmodified。 |
--null-string '\\N' | The string to be written for a null value for string columns 要为字符串列的空值写入的字符串 详细信息见官网7.2.12. Importing Data Into Hive |
更新中。。。
官网地址:http://sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html#_importing_data_into_hive