1)Python DB API : Python访问数据库的统一接口规范。
https://www.python.org/dev/peps/
2)Python DatabaseInterfaces:
https://wiki.python.org/moin/DatabaseInterfaces
------------------------------------------
1)要想用Python操作mysql,就需要安装MySQL-python驱动,它是Python操作Mysql必不可少的模块。目前windows版的只提供32位的安装文件,所以你的Python也需要时32位的,64位无法工作。
下载地址:https://pypi.python.org/pypi/MySQL-python/
下载MySQL-python-1.2.5.zip 文件之后直接解压。进入MySQL-python-1.2.5目录:
>>python setup.py install
2)测试一下MySQLdb模块是否已经正常导入。
>>> import MySQLdb
如果没有错误提示则表明已经正常导入。
3)下面是可以参考的操作数据库的Python代码。
#coding=utf-8
import MySQLdb
conn= MySQLdb.connect(
host='localhost',
port = 3306,
user='root',
passwd='123456',
db ='test',
)
cur = conn.cursor()
#创建数据表
#cur.execute("create table student(id int ,name varchar(20),class varchar(30),age varchar(10))")
#插入一条数据
#cur.execute("insert into student values('2','Tom','3 year 2 class','9')")
#修改查询条件的数据
#cur.execute("update student set class='3 year 1 class' where name = 'Tom'")
#删除查询条件的数据
#cur.execute("delete from student where age='9'")
cur.close()
conn.commit()
conn.close()