使用實(shí)現(xiàn)python連接hive數(shù)倉的示例代碼
1 版本參數(shù)
查看hadoop和hive的版本號(hào)
ls -l /opt # 總用量 3 # drwxr-xr-x 11 root root 227 1月 26 19:23 hadoop-3.3.6 # drwxr-xr-x 10 root root 205 2月 12 18:53 hive-3.1.3 # drwxrwxrwx. 4 root root 32 2月 11 22:19 tmp
查看java版本號(hào)
java -version # java version "1.8.0_391" # Java(TM) SE Runtime Environment (build 1.8.0_391-b13) # Java HotSpot(TM) 64-Bit Server VM (build 25.391-b13, mixed mode)
查看mysql版本號(hào)
mysql --version # mysql Ver 8.0.35 for Linux on x86_64 (MySQL Community Server - GPL)
2 啟動(dòng)環(huán)境
啟動(dòng)hadoop集群
start-all.sh # WARNING: HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USER. Using value of HADOOP_SECURE_DN_USER. # Starting namenodes on [ml] # 上一次登錄:三 3月 6 23:34:59 CST 2024tty1 上 # Starting datanodes # 上一次登錄:三 3月 6 23:37:56 CST 2024pts/0 上 # Starting secondary namenodes [ml] # 上一次登錄:三 3月 6 23:38:01 CST 2024pts/0 上 # Starting resourcemanager # 上一次登錄:三 3月 6 23:38:30 CST 2024pts/0 上 # Starting nodemanagers # 上一次登錄:三 3月 6 23:39:01 CST 2024pts/0 上
查看hadoop集群狀態(tài)
jps|sort # 2337 NameNode # 2548 DataNode # 3161 ResourceManager # 3379 NodeManager # 5654 Jps
啟動(dòng)hiveserver2服務(wù)
nohup hiveserver2 & # [1] 7486 # (pyspark) (base) [root@~ ~]# nohup: 忽略輸入并把輸出追加到"nohup.out" #
檢測hiveserver2狀態(tài)
jps|grep 7486 # 7486 RunJar
檢測thrift端口號(hào)狀態(tài)
netstat -anp|grep 10000 # tcp6 0 0 :::10000 :::* LISTEN 7486/java
3 安裝環(huán)境
安裝python第三方庫
conda install sasl conda install thrift conda install thrift-sasl conda install pyhive conda install sqlalchemy conda install pandas
使用everything檢索sasl2文件夾并打開該文件夾
在open git bash here窗口查看sasl2里面的文件
ls # saslANONYMOUS.dll* saslLOGIN.dll* saslPLAIN.dll* saslSQLITE.dll* # saslCRAMMD5.dll* saslNTLM.dll* saslSASLDB.dll* saslSRP.dll* # saslDIGESTMD5.dll* saslOTP.dll* saslSCRAM.dll*
創(chuàng)建C:/CMU/bin/sasl2文件夾
拷貝當(dāng)前文件夾的dll文件到C:/CMU/bin/sasl2文件夾中
mkdir -p C:/CMU/bin/sasl2 cp ./* C:/CMU/bin/sasl2/
4 讀取數(shù)據(jù)
編寫python腳本連接hive數(shù)倉
import pandas as pd
from pyhive import hive
from sqlalchemy import create_engine
engine = create_engine('hive://root:ml123456@ml:10000/default?auth=LDAP')
df = pd.read_sql_query('show databases',con=engine)
df.head()
能看到數(shù)據(jù)庫名記錄就證明連接成功
到此這篇關(guān)于使用實(shí)現(xiàn)python連接hive數(shù)倉的示例代碼的文章就介紹到這了,更多相關(guān)python連接hive數(shù)倉內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python自動(dòng)化測試框架之unittest使用詳解
unittest是Python自動(dòng)化測試框架之一,提供了一系列測試工具和接口,支持單元測試、功能測試、集成測試等多種測試類型。unittest使用面向?qū)ο蟮乃枷雽?shí)現(xiàn)測試用例的編寫和管理,可以方便地?cái)U(kuò)展和定制測試框架,支持多種測試結(jié)果輸出格式2023-04-04
使用Python+Splinter自動(dòng)刷新12306火車票
一年一度的春運(yùn)又來了,今年我自己寫了個(gè)搶票腳本,下面小編給大家分享使用Python+Splinter自動(dòng)刷新12306火車票,需要的朋友參考下吧2018-01-01
在Python中實(shí)現(xiàn)Redis鍵值對添加和刪除的操作指南
本指南詳解了Python中Redis鍵值對操作,對比DELETE與UNLINK性能差異,推薦使用UNLINK處理大型數(shù)據(jù),結(jié)合管道和過期時(shí)間優(yōu)化效率,強(qiáng)調(diào)連接復(fù)用與內(nèi)存管理,需要的朋友可以參考下2025-08-08
pytorch讀取圖像數(shù)據(jù)轉(zhuǎn)成opencv格式實(shí)例
這篇文章主要介紹了pytorch讀取圖像數(shù)據(jù)轉(zhuǎn)成opencv格式實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06
Python通過命令開啟http.server服務(wù)器的方法
這篇文章主要給大家介紹了關(guān)于Python通過命令開啟http.server服務(wù)器的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11

