import pymysql
import phoenixdb.cursor
from datetime import datetime

# 建立MySQL数据库连接
mysql_connection = pymysql.connect(
    host='localhost',
    user='root',
    password='root',
    database='test',
    charset='utf8mb4'
)
# 建立Phoenix数据库连接
phoenix_connection = phoenixdb.connect('http://192.168.126.100:8765/', autocommit=True)
phoenix_cursor = phoenix_connection.cursor()

try:
    # 创建MySQL游标对象
    mysql_cursor = mysql_connection.cursor()

代码解读内容:

  1. 引入 pymysqlphoenixdb.cursor 模块,以及 datetime 模块。
  2. 建立 MySQL 数据库连接,连接到本地的 test 数据库,使用 utf8mb4 编码。
  3. 建立 Phoenix 数据库连接,连接到 IP 为 192.168.126.100,端口为 8765 的 Phoenix 数据库,设置自动提交。
  4. 创建 MySQL 游标对象。
  5. 异常处理。
Python 连接 MySQL 和 Phoenix 数据库示例

原文地址: https://www.cveoy.top/t/topic/oHce 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录