说明
之前python的项目使用的mysql,近期要切换到国产数据库OpenGauss。
之前的方案是fastapi+sqlalchemy,测试下来发现不用改代码,只要改下配置即可。
切换方案
安装openGauss-connector-python-psycopg2
其代码工程在:https://gitee.com/opengauss/openGauss-connector-python-psycopg2#%E5%AE%89%E8%A3%85-psycopg2
也可以直接下载华为编译好的包,下载网页在:https://opengauss.org/zh/download/。解压安装包后,会得到两个目录 lib 和 psycopg2。
# 通过如下指令来查找 site-packages 目录所在位置:
python -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"
#输出/usr/local/lib/python3.9/site-packages
#将 psycopg2 文件夹整个拷贝该目录下,并授权便于其他用户使用
cp -r psycopg2 /usr/local/lib/python3.9/site-packages/
chmod 755 /usr/local/lib/python3.9/site-packages/psycopg2
# 将解压得到的lib目录加到LD_LIBRARY_PATH中
echo "export LD_LIBRARY_PATH=/path/to/lib/:$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc
若不需要使用autoescape相关功能,则不用安装openGauss-connector-python-psycopg2,直接装psycopg2-binary就行:
pip install psycopg2-binary
安装opengauss-sqlalchemy
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
python -m pip install opengauss-sqlalchemy
使用新URL
DATABASE_URI=opengauss://mygaussdbusername:passwd0123@10.xx.xx.xx:9xxx/mybasename






![[创业之路-344]:战略的本质是选择、聚焦, 是成本/效率/低毛利优先,还是差易化/效益/高毛利优先?无论是成本优先,还是差易化战略,产品聚焦是前提。](https://i-blog.csdnimg.cn/direct/2f1e278ce98d4f0ab2329af51beb1994.png)









![[Java微服务架构]4_服务通信之客户端负载均衡](https://i-blog.csdnimg.cn/direct/2feeeb2030f44360a9df25de2035636d.png)


