栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python与数据库的交互方法--pyDAL库

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python与数据库的交互方法--pyDAL库

1.安装pyDAL库

pip install pyDAL

2.pyDAL库的强大之处在于,它可以和各种数据库进行交互,而且代码非常容易移植。

连接各个数据库的方法如下:(在如下表中,我们统一假设数据库登录的账户为username,登录密码为password,主机地址为(host address)localhost,登录后数据库的名字为test)。详细用法见如下链接。

web2py - The database abstraction layer

SQLitesqlite://storage.sqlite
MySQLmysql://username:password@localhost/test?set_encoding=utf8mb4
PostgreSQLpostgres://username:password@localhost/test
MSSQL (legacy)mssql://username:password@localhost/test
MSSQL (>=2005)mssql3://username:password@localhost/test
MSSQL (>=2012)mssql4://username:password@localhost/test
FireBirdfirebird://username:password@localhost/test
Oracleoracle://username/password@test
DB2db2://username:password@test
Ingresingres://username:password@localhost/test
Sybasesybase://username:password@localhost/test
Informixinformix://username:password@test
Teradatateradata://DSN=dsn;UID=user;PWD=pass;DATABASE=test
Cubridcubrid://username:password@localhost/test
SAPDBsapdb://username:password@localhost/test
IMAPimap://user:password@server:port
MongoDBmongodb://username:password@localhost/test
Google/SQLgoogle:sql://project:instance/database
Google/NoSQLgoogle:datastore
Google/NoSQL/NDBgoogle:datastore+ndb

3.本文以MySQL为例子实现对数据库的交互:

        首先连接MySQL数据库,下图是用MySQL数据库的数据库交互平台,这些平台都大同小异,任意选一个下载安装即可。数据库的平台在主机上搭建一个server,然后其他电脑就可以通过client客户端访问了。我这里用的是HeidiSQL客户端:(如下可知,我的登录的账户为root,登录密码为*****,主机地址为192.168.0.45

 登录后数据库的名字为pqlongtermtest,然后我在下面建立了许多个table,

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/925754.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号