# python-database-drivers-demo **Repository Path**: thepoy/python-database-drivers-demo ## Basic Information - **Project Name**: python-database-drivers-demo - **Description**: python各数据库驱动使用模板 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-28 - **Last Updated**: 2021-12-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 用过的各种数据库驱动的使用示例 ## 1 MySQL ### (1) pymysql ```bash pip install pymysql ``` 参考 [mysql_pymysql.py](https://gitee.com/thepoy/python-database-drivers-demo/blob/master/mysql_pymysql.py) ### (2) mysql-connector ```bash pip install mysql-connector ``` 参考 [mysql_mysql-connector.py](https://gitee.com/thepoy/python-database-drivers-demo/blob/master/mysql_mysql-connector.py) ## 2 PostgreSQL ### (1) psycopg psycopg 默认为最新的版本,当前是 psycopg3。 ```bash pip install psycopg ``` 如果想用 psycopg2,需要单独安装 psycopg2: ```bash pip install psycopg2 ``` 但本仓库没有写 psycopg2 示例。 psycopg3 分为同步和异步两个示例: - 同步:[postgresql_psycopg_sync.py](https://gitee.com/thepoy/python-database-drivers-demo/blob/master/postgresql_psycopg_sync.py) - 异步:[postgresql_psycopg_async.py](https://gitee.com/thepoy/python-database-drivers-demo/blob/master/postgresql_psycopg_async.py) > 如果在 Windows 中连接 PostgreSQL 时用时太长,可以尝试在 DSN 中添加 gssencmode=disable