本博客主要介紹Hive和MySql的搭建: html
學習視頻一天就講完了,我看完了本身搭建MySql遇到了一堆坑,而後花了快兩天才解決完,終於把MySql搭建好了。而後又去搭建Hive,又遇到了不少坑,就這樣一直解決問題,加上網上搜索和我的排查檢查日誌。搜索百度,百度不行搜索Bing,看了csdn,看strackflow,最後終於功夫不負有心人,成功把MySql和Hive跑起來了。這裏我將還原最初狀態,並把遇到的坑一併記錄下,同時防止後人採坑。java
搭建環境:mysql
Centos7,MySql14.14,Hive2.3.6 web
搭建MySql:sql
搭建步驟我參考的菜鳥教程: https://www.runoob.com/mysql/mysql-install.html數據庫
參考上述步驟搭建遇到的坑:apache
坑1:安裝完後,給root用戶設置密碼後,使用帳戶和密碼登錄報了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)錯誤,解決方案點擊。vim
搭建Hive:oop
搭建步驟我參考的: http://www.javashuo.com/article/p-eksivokj-bd.html學習
參考上述步驟遇到的坑:啓動hive拋出Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D異常,解決方案點擊。
操做Hive:
先說下環境的坑:
坑1:當我在Hive中執行查詢操做沒問題,可是當刪除表結構的時候會拋出以下異常 :
執行drop table tableName;
Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)
這句話的意思是不支持此操做,並非SQL寫錯了。 這個問題的緣由是以前咱們在hive的lib中添加的mysql-connection-java.jar(使用JDBC操做MySql的包)版本不對,我以前用的mysql-connection-java-5.1.18.jar,後來改成了mysql-connection-java-5.1.47.jar就行了。
若是您的也不對,請及時替換,包鏈接
案例1(在Hive中建立內部表):
在Linux系統找個位置建立visits.txt和visits.hive文件:
在visits.txt文件裏面加入以下內容,中間是以\t 分割的
一明 18701223481 北京市朝陽區 毒逆天 18498778212 江蘇省蘇州市 海面貝貝 15099334981 上海市閔行區
在visits.hive加入建立數據庫命令
create table people_visits ( user_name string, phone string, address string ) row format delimited fields terminated by '\t';
在hive裏面建立people_visits表
hive -f visits.hive
而後在hive中使用show tables; 就能看到這個表了。 可是數據是空的。接下來使用命令將visits.txt文件數據提交到hdfs再查詢就能看到數據了。
hadoop fs -put visits.txt /user/hive/warehouse/people_visits
使用web瀏覽也能夠看到上傳的文件:
案例2:(在hive中建立外部表)
在Linux本地找個文件夾建立externalHive.txt文件
cd /data/
touch externalHive.txt
編輯文件加入如下內容
vim externalHive.txt
西紅柿 11 桃子 22
注意:(上面字符使用tab鍵分割)
在hdfs裏面新建一個hivetest文件夾
hadoop fs -mkdir /user/root/hivetest
將文件上傳到hdfs
hadoop fs -put externalHive.txt /user
進入Hive建立一個價格外部表
hive
create external table priceVisits ( name string, price int ) row format delimited fields terminated by '\t' location '/user/root/hivetest'; --指定表所在路徑
將數據上傳到priceVisits表裏面
hive
load data inpath '/user/externalHive.txt' into table priceVisits;
PS:(上面的命令執行完後,user目錄下的externalHive.txt就會移動到建立table時指定的目錄下面)
查詢priceVisits表就能夠看到數據了
select *from priceVisits;
刪除priceVisits表:
drop table priceVisits;
能夠看到表刪除了,可是數據還沒刪除,這就是外部表的做用
案例3:綜合查詢
上面的查詢並無用到MapReduce計算,僅僅使用了簡單的本地查詢,這是由於咱們沒有寫聚合語句,不須要MapReduce。 接下來寫個須要MapReduce的案例。
其它操做語句參考博客: http://www.javashuo.com/article/p-nwhnrxlc-db.html
分桶操做參考: https://blog.csdn.net/u010003835/article/details/80911215