濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > hive從mysql導(dǎo)入數(shù)據(jù)量變多的解決方案

hive從mysql導(dǎo)入數(shù)據(jù)量變多的解決方案

熱門標(biāo)簽:地圖標(biāo)注被騙三百怎么辦 云南語音外呼系統(tǒng)平臺(tái) 常州電銷外呼系統(tǒng)一般多少錢 北京人工外呼系統(tǒng)價(jià)錢 沃克斯電梯外呼線路圖 福州呼叫中心外呼系統(tǒng)哪家好 房產(chǎn)智能外呼系統(tǒng)品牌 400電話鄭州申請 天智外呼系統(tǒng)

原始導(dǎo)數(shù)命令:

bin/sqoop import -connect jdbc:mysql://192.168.169.128:3306/yubei -username root -password 123456 -table yl_city_mgr_evt_info --split-by rec_id -m 4 --fields-terminated-by "\t" --lines-terminated-by "\n" --hive-import --hive-overwrite -create-hive-table -delete-target-dir -hive-database default -hive-table yl_city_mgr_evt_info

原因分析:可能是mysql中字段里面有'\n'等分隔符,導(dǎo)入hive時(shí)默認(rèn)以'n'作換行符,導(dǎo)致hive中的記錄數(shù)變多。

解決方法:

導(dǎo)入數(shù)據(jù)時(shí)加上--hive-drop-import-delims選項(xiàng),會(huì)刪除字段中的\n,\r,\01。

最終導(dǎo)數(shù)命令:

bin/sqoop import -connect jdbc:mysql://192.168.169.128:3306/yubei -username root -password 123456 -table yl_city_mgr_evt_info --split-by rec_id -m 4 --hive-drop-import-delims --fields-terminated-by "\t" --lines-terminated-by "\n" --hive-import --hive-overwrite -create-hive-table -delete-target-dir -hive-database default -hive-table yl_city_mgr_evt_info

參考官方文檔:https://sqoop.apache.org/docs/1.4.7/SqoopUserGuide.html

補(bǔ)充:Sqoop導(dǎo)入MySQL數(shù)據(jù)到Hive遇到的坑

1.sqoop導(dǎo)入到HDFS

1.1執(zhí)行sqoop job,會(huì)自動(dòng)更新last value

# sqoop 增量導(dǎo)入腳本
bin/sqoop job --create sqoop_hdfs_test02 -- import \

--connect jdbc:mysql://localhost:3306/pactera_test \

--username root \

--password 123456 \

--table student \

--target-dir /user/sqoop/test002/ \

--fields-terminated-by "\t" \

--check-column last_modified \

--incremental lastmodified \

--last-value "2018-12-12 00:03:00" \

--append

說明:--append 參數(shù)是必須的,要不然第二次運(yùn)行job 會(huì)報(bào)錯(cuò),如下:

至此,sqoop job 已建設(shè)完畢!

2.Hive創(chuàng)建表,并讀取sqoop導(dǎo)入的數(shù)據(jù)

create external table if not exists student_hive (SId int,Sname string ,Sage string,Ssex string , last_modified Timestamp) 
row format delimited fields terminated by '\t' location 'hdfs://node01:8020/user/sqoop/test002/';

注意:此處hive中時(shí)間的格式為timestamp,設(shè)置為date DB數(shù)據(jù)無法正常加載。

第一次全量加載,整條路線完全OK,hive表可以查詢到數(shù)據(jù)。

-----------------------重點(diǎn)分割線-----------------------

* sqoop lastmodified格式的增量加載,會(huì)將last-value 保存為job執(zhí)行的系統(tǒng)時(shí)間,若測試數(shù)據(jù)庫的check-column 小于當(dāng)前系統(tǒng)時(shí)間(即上一個(gè)job的last-value),則數(shù)據(jù)將不被加載。

如SId=6 就沒有被加載,遂改為今日時(shí)間(2018-12-26 17:05)進(jìn)行數(shù)據(jù)測試,數(shù)據(jù)成功被加載!喲呵?。?/p>

總結(jié):

使用lastmodified格式,進(jìn)行sqoop增量導(dǎo)入時(shí),

1.注意--append的使用;

2.last-value為job運(yùn)行的系統(tǒng)時(shí)間,在數(shù)據(jù)測試時(shí),要保證數(shù)據(jù)的準(zhǔn)確,數(shù)據(jù)的自增長。

3.一切皆有定數(shù),查看資料,準(zhǔn)確定位自己系統(tǒng)遇到的問題

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • MySQL如何快速導(dǎo)入數(shù)據(jù)
  • MySQL 4種導(dǎo)入數(shù)據(jù)的方法
  • mysql如何利用Navicat導(dǎo)出和導(dǎo)入數(shù)據(jù)庫的方法
  • Java利用MYSQL LOAD DATA LOCAL INFILE實(shí)現(xiàn)大批量導(dǎo)入數(shù)據(jù)到MySQL
  • MySQL命令行導(dǎo)出導(dǎo)入數(shù)據(jù)庫實(shí)例詳解
  • wampserver下mysql導(dǎo)入數(shù)據(jù)庫的步驟
  • MySQL命令行導(dǎo)出與導(dǎo)入數(shù)據(jù)庫
  • 使用mysqldump導(dǎo)入數(shù)據(jù)和mysqldump增量備份(mysqldump使用方法)
  • MYSQL 導(dǎo)入數(shù)據(jù)的幾種不同
  • 修改php.ini實(shí)現(xiàn)Mysql導(dǎo)入數(shù)據(jù)庫文件最大限制的修改方法
  • .Net Core導(dǎo)入千萬級(jí)數(shù)據(jù)至Mysql的步驟

標(biāo)簽:移動(dòng) 鹽城 沈陽 徐州 珠海 拉薩 沈陽 黔東

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《hive從mysql導(dǎo)入數(shù)據(jù)量變多的解決方案》,本文關(guān)鍵詞  hive,從,mysql,導(dǎo)入,數(shù)據(jù),量變,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《hive從mysql導(dǎo)入數(shù)據(jù)量變多的解決方案》相關(guān)的同類信息!
  • 本頁收集關(guān)于hive從mysql導(dǎo)入數(shù)據(jù)量變多的解決方案的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    长寿区| 奉化市| 东明县| 寿宁县| 怀仁县| 静海县| 广德县| 安岳县| 洪洞县| 呼和浩特市| 类乌齐县| 西藏| 荆门市| 大石桥市| 咸阳市| 浠水县| 新安县| 苍溪县| 巴马| 衡阳县| 安福县| 明溪县| 邵阳市| 江陵县| 应城市| 惠州市| 阳朔县| 江达县| 和硕县| 亳州市| 垣曲县| 阿鲁科尔沁旗| 泸西县| 武夷山市| 措勤县| 乐至县| 循化| 石门县| 肃南| 临沧市| 丰原市|