环境
GBase版本:Gbase8s_华为鲲鹏
Python版本:2.7.16
pymysql版本:0.9.3
sqlalchemy版本:1.3.1
方法
GBase的访问采用pymysql插件,比如
import pymysql
connetction = pymysql.connect(host=‘localhost’, port=5258, user=‘xxx’, password=‘xxxxx’, db = ‘gbase’, charset=‘utf8mb4’, unix_socket=’/opt/GBase/Server/tmp/gbase.sock’);
而在sqlalchemy的链接为
sql_connection = mysql+pymysql://xxx:xxxxx@xxx.xxx.xxx.xxx:5258/xxx
本文介绍了如何在Python环境下,使用sqlalchemy连接GBase数据库。通过pymysql作为GBase的适配器,详细阐述了连接参数设置,包括host、port、user、password、db、charset和unix_socket等。同时,展示了传统pymysql连接方式与sqlalchemy的连接字符串格式差异。
4万+





