Python 数据库连接(sqlite, mysql, oracle, postgresql, sql server)
Python连接数据主要用SQLAlchemy。
SQLAlchemy是最有名的ORM框架。
首先通过pip或easy_install 安装 SQLAlchemy
pip install sqlalchemy
数据库连接
from sqlalchemy import create_engine
# 连接 sqlite内存数据库
engine = create_engine('sqlite:///:memory:')
# 连接 sqlite文件数据库
# where is relative:
engine = create_engine('sqlite:///foo.db')
# or absolute, starting with a slash:
engine = create_engine('sqlite:absolute/path/to/foo.db')
# 连接 mysql
engine = create_engine('mysql+mysqldb://scott:tiger@localhost/foo')
#连接 oracle
engine = create_engine('oracle://scott:tiger@127.0.0.1:1521/sidname')
#连接SQL Server
engine = create_engine('mssql+pyodbc://mydsn')
#or
engine &#

本文介绍了如何使用Python的SQLAlchemy库连接到各种数据库,包括SQLite, MySQL, Oracle, SQL Server和PostgreSQL。详细阐述了数据库驱动的安装和配置,例如cx_Oracle库在Mac上的安装过程,以及pymssql和MySQLdb的安装方法。"
114395003,10715206,亚马逊测评防关联浏览器推荐,"['指纹浏览器', '亚马逊测评', '跨境电商', '浏览器插件', '防关联工具']
最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



