參考:
#簡單
#複雜點的
方法一:
ali-bigdata-gateway-guard-1
deactivate
sudo -i
. /mnt/disk1/data/venv_bi/bin/activate
pip install pyhive
pip install thrift
pip install sasl
pip install thrift_sasl
vim h.py
from pyhive import hive
conn = hive.connection(host='127.0.0.1', port=10000, username='feng.hong', database='test_db')
cursor = conn.cursor()
cursor.execute('show databases')
print(cursor.fetchall())
或使用select查詢
conn = hive.connection(host='127.0.0.1', port=10000, username='feng.hong', database='test_db')
cursor = conn.cursor()
cursor.execute('select * from users limit 10')
print(cursor.fetchall())
#長的查詢語句可用三個引號表示忽略換行
#設定佇列可以新起乙個execute,因為是在同乙個connect中所以不會失效.
from pyhive importhive
conn= hive.connection(host='10.52.5.190', port=10000, username='feng.hong', database='default')
cursor=conn.cursor()
cursor.execute('set mapreduce.job.queuename=data_bi')
cursor.execute("""select
a.dt,
a.city_id,
a.city_name,
a.product_id,
a.driver_id,
a.phone_number
from oride_dw.dim_oride_driver_base a
where a.dt=date_sub(from_unixtime(unix_timestamp(),'yyyy-mm-dd'),6) limit 10""")print(cursor.fetchall())
方法二:通過os.system,具體見部落格python發郵件
os.system("hive -e \"set mapreduce.job.queuename=data_bi;select a.dt,a.city_id,a.city_name,a.product_id,a.driver_id,a.phone_number from oride_dw.dim_oride_driver_base a where a.dt >= date_sub(current_date(),2) and a.dt<= date_sub(current_date(),1) limit 10\" >/tmp/1.txt")
方法三: 沒跑出來,待研究
"""表示注釋
import pandas as pd
import sqlalchemy as sa
sql = """select a.dt, a.city_id, a.city_name, a.product_id, a.driver_id, a.phone_number
from oride_dw.dim_oride_driver_base a
where a.dt=date_sub(from_unixtime(unix_timestamp(),'yyyy-mm-dd'),6) limit 10"""
engine = sa.create_engine('hive:')
pd.read_sql(sql, engine)
Python基礎 Python連線MySQL
什麼是 pymysql?pymysql 是在 python3.x 版本中用於連線 mysql 伺服器的乙個庫,python2中則使用mysqldb。pymysql 遵循 python 資料庫 api v2.0 規範,幷包含了 pure python mysql 客戶端庫。pymysql 安裝 在使用...
python 反向連線後門
1 首先daemon化2 然後用 netstat命令,檢測是否指定的ip 192.168.1.111 連線上,有,則啟用無,則睡眠幾分鐘 這個時間可根據需要自行調節 3 啟用後,開乙個子程序,建立socket,與執行了監聽程式的ip進行連線,並執行乙個shell,將該shell的輸入輸出重定向到so...
Python 自動連線ssh
usr bin python coding utf 8 import sys,time,os try import pexpect except importerror print you must install pexpect module sys.exit 1 addr map try key...