本篇文章python连接操作各种数据基于python3.8版本
一、Python与Oracle交互
二、Python与Mysql交互
import pymysql
try:
conn = pymysql.connect(
host = 'localhost'
port = 3306
user = 'test'
password = 'test'
database = 'mysql'
)
except pymysql.err.OperationalError as err:
print('Connecttion Mysql Failed: {}'.format(err))
cursor = conn.cursor()
#执行Sql
cursor.execute();
三、Python与PostgresSql交互
import psycopg2
conn = psycopg2.connect(
host = 'localhost'
port = 3306
user = 'test'
password = 'test'
database = 'mysql'
)
cursor = conn.cursor()
#执行Sql
cursor.execute();
四、Python与OceanBase交互
连接OceanBase稍微复杂一点,需要准备个jar包,我这里用的如下所示,连接的是Oceanbase4.2版本
- oceanbase-client-2.4.7.1.jar
import jaydebeapi
url='jdbc:oceanbase://host:port'
driver = 'com.alipay.oceanbase.jdbc.Driver'
user = 'test'
password = 'test'
jar = './jar/oceanbase-client-2.4.7.1.jar'
conn = jaydebeapi.connect(
driver,
url,
[user,password],
jar
)
cursor = conn.cursor()
#执行Sql
cursor.execute();