发布网友 发布时间:2022-04-07 21:21
共2个回答
懂视网 时间:2022-04-08 01:42
CREATE TABLE `YHD_CATEG_PRIOR` ( `category_id` int(11) NOT NULL COMMENT ‘类目ID‘, `category_name` varchar(250) DEFAULT NULL COMMENT ‘类目名称‘, `category_level` int(11) DEFAULT ‘0‘ COMMENT ‘类目级别‘, `default_import_categ_prior` int(11) DEFAULT ‘0‘ COMMENT ‘默认引入优先级‘, `user_import_categ_prior` int(11) DEFAULT NULL COMMENT ‘用户引入优先级‘, `default_eliminate_categ_prior` int(11) DEFAULT NULL COMMENT ‘默认淘汰优先级‘, `user_eliminate_categ_prior` int(11) DEFAULT NULL COMMENT ‘用户淘汰优先级‘, `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘数据刷新时间‘, PRIMARY KEY (`category_id`) ) ENGINE=InnoDB AUTO_INCREMENT=61125 DEFAULT CHARSET=utf8;现在需要将数据表YHD_CATEG_PRIOR导入到Hive中。
脚本如下:
# 创建Hive数据表pms.yhd_categ_prior_user
hive -e "
set mapred.job.queue.name=pms;
set mapred.job.name=[CIS]yhd_categ_prior_user;
-- Hive DDL
DROP TABLE IF EXISTS pms.yhd_categ_prior_user;
CREATE TABLE pms.yhd_categ_prior_user
(
category_id bigint,
category_name string,
category_level int,
default_import_categ_prior int,
user_import_categ_prior int,
default_eliminate_categ_prior int,
user_eliminate_categ_prior int,
update_time string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘ ‘
LINES TERMINATED BY ‘
‘
STORED AS TEXTFILE;"
# 同步mysql的market.YHD_CATEG_PRIOR到hive中
hadoop fs -rmr /user/pms/YHD_CATEG_PRIOR
sqoop import -Dmapred.job.queue.name=pms --connect jdbc:mysql://127.0.0.1:3306/market
--username admin
--password 123456
--table YHD_CATEG_PRIOR
--hive-table pms.yhd_categ_prior_user
--fields-terminated-by ‘ ‘
--lines-terminated-by ‘
‘
--hive-overwrite
--hive-drop-import-delims
--hive-import
上述的脚本工作流程:
col_name data_type comment
# col_name data_type comment
category_id bigint None
category_name string None
category_level int None
default_import_categ_prior int None
user_import_categ_prior int None
default_eliminate_categ_prior int None
user_eliminate_categ_prior int None
update_time string None
# Detailed Table Information
Database: pms
Owner: pms
CreateTime: Fri Jun 05 18:48:01 CST 2015
LastAccessTime: UNKNOWN
Protect Mode: None
Retention: 0
Location: hdfs://yhd-jqhadoop2.int.yihaodian.com:8020/user/hive/pms/yhd_categ_prior_user
Table Type: MANAGED_TABLE
Table Parameters:
numFiles 5
numPartitions 0
numRows 0
rawDataSize 0
totalSize 447779
transient_lastDdlTime 1433501435
# Storage Information
SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat: org.apache.hadoop.mapred.TextInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
Storage Desc Params:
field.delim
line.delim
serialization.format
[Sqoop]将Mysql数据表导入到Hive
标签:
热心网友 时间:2022-04-07 22:50
sqoop导入mysql中表不需要手动创建。连接到hive的默认数据库后会自动创建的。Sqoop是一个用来将Hadoop和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库(例如