python 3接続mysql,oracle,hive
2885 ワード
一、python 3接続mysql
二、python 3接続oracle
python 3接続hive
import MySQLdb
localhost = "10.79.2.40"
user = "root"
pwd = "root"
database = "mytest"
TABLE_NAME = "mytable"
conn = MySQLdb.connect(localhost,user,pwd,database,charset='utf8')
cursor = conn.cursor()
cursor.execute('SELECT * FROM %s WHERE FLAG = "Y"' %TABLE_NAME)
pairedlotflag = cursor.fetchall()
二、python 3接続oracle
import os
import cx_Oracle as oracle
# os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' #
# os.environ['path'] = 'F:/MyTools/instantclient-12.2/instantclient_12_2/' #
or_cnn = oracle.connect("fabadm/[email protected]/unixtst") # / @ /
cursor = or_cnn.cursor()
cursor.execute('select ARRAYPRODUCTNAME from bsodfpairinfo where rownum <10')
data = cursor.fetchone()
data = cursor.fetchall()
python 3接続hive
from pyspark.sql import HiveContext
from pyspark import SparkConf, SparkContext
sc = SparkContext()
hiveContext = HiveContext(sc)
sql = "select * from table limit 3"
data = hiveContext.sql(sql_all)
data.show()
sc.stop()