#reading
import MySQLdb
db= MySQLdb.connect(host="localhost", user="python-test", passwd="python",db="python-test")#连接
cursor = db.cursor()
stmt = "SELECT * from books"
cursor.execute(stmt)#执行动作
rows = cursor.fetchall ()
for row in rows:
print "Row: "
for col in row :
print "Column: %s" % (col)
print "End of Row"
print "Number of rows returned: %d" % cursor.rowcount
cursor.close()
db.close() #关闭
#updating
import MySQLdb
import MySQLdb.cursors
def get_column_name( data, prompt, names ) :
value=-1
while value == -1:
idx = 1
for col in data :
print str(idx) + ": " + col
names.append( col )
idx = idx + 1
value = int( raw_input(prompt) )
if value < 1 or value >= idx :
value = -1
return value
conn = MySQLdb.Connect(host='localhost',user='root',passwd='',db='dragon') #连接
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute("SELECT * FROM books")
data = cursor.fetchone()
names = []
old_value = get_column_name( data, "Which column do you want to change records for? ", names )
names = []
new_value = get_column_name( data, "Which column do you want to change records to? ", names )
old_val = raw_input("What value do you want to change for " + names[old_value-1] + ": ")
new_val = raw_input("What value do you want to change to for " + names[new_value-1] + ": ")
stmt = "UPDATE books SET " + names[new_value-1] + " = '"+ new_val + "' WHERE " + names[old_value-1] + " = '" + old_val + "'"
print stmt
cursor.execute(stmt)
print "Rows affected: " + str(cursor.rowcount)
cursor.close()
conn.commit()
conn.close()
#writing
import MySQLdb
db= MySQLdb.connect(host="localhost", user="python-test", passwd="python",
db="python-test")
try:
title = raw_input("Please enter a book title: ")
if title == "" :
exit
author = raw_input("Please enter the author's name: ")
pubdate = int( raw_input("Enter the publication year: ") )
except:
print "Invalid value"
exit
print "Title: [" + title + "]"
print "Author: ["+ author + "]"
print "Publication Date: " + str(pubdate)
cursor = db.cursor()
stmt = "INSERT INTO Books (BookName, BookAuthor, PublicationDate) VALUES ('"
stmt = stmt + title
stmt = stmt + "', '"
stmt = stmt + author
stmt = stmt + "', "
stmt = stmt + str(pubdate)
stmt = stmt + ")"
cursor.execute(stmt)
print "Record added!"
cursor.close ()
db.commit ()
分享到:
相关推荐
这个包里有两个包,都可以用来在windows上安装python-MySQLdb,选择其中一种就可以!我比较喜欢用-master那个包,因为只要解压后执行python setup.py install就可以了。另一个包在安装时若出现找不到python2.7的安装...
连接MySQLdb1-MySQLdb-1.2.5.zip MySQLdb1-MySQLdb-1.2.5.zip MySQLdb1-MySQLdb-1.2.5.zip MySQLdb1-MySQLdb-1.2.5.zip
MysqlDB pymysql操作类库
python2.6-MySQLdb,包括python2.6安装包、MySQLdb for python2.6安装包、MySQLdb使用配置,为想学习Python操作mysql数据库的同学提供了极大的方便。。。
python安装模块MySQLdb时,提示python2.7未安装,安装失败时,命令行python register.py,然后重新安装MySQLdb,就能正确安装。
官方mysqldb用户手册,英文版,方便使用
windows环境下配置python3 mysqldb
MySQLdb 1.2.3 for Python 2.7 (Windows)
MySQLdb模块英文版使用手册,内置搜索功能,方便查找定位使用语法
python连接mysql数据库需要MySQLdb win7 64位安装好就可以用了。 具体代码可以参考:http://www.runoob.com/python/python-mysql.html
windows mysqldb for python2.5 in windows
python3.6使用MySQLdb连接mysql需要mysqlclient-1.3.12-cp36-cp36m-win_amd64.whl
鸟人封装的MySQLdb操作接口,包含读写分离、断线重连的逻辑,对于具体应用可以继承和扩展
2021_w_.1.python 驱动MySQLdb(create_engine)代码
mysqldb,對python2提供的mysql驅動,目前只支持到python3.3以下版本
资源来自pypi官网。 资源全名:mysqldb-rich-2.7.tar.gz
Lepus(天兔)数据库企业监控系统是一套由专业DBA个人(目前就职于某互联网公司),针对互联网企业开发的一款专业、强大的企业数据库监控管理系统,.MySQLdb是一款较为底层的,python连接mysql用的模块。
MySQLdb包在python3.7版本下的安装包, 进入对应目录下后,pip install mysqlclient-2.0.2-cp37-cp37m-win_amd64.whl安装
在使用python调用mysql数据库的时候,需要引入对应的数据包,这个包包含了python的64位和32位mysqldb库,
资源分类:Python库 所属语言:Python 资源全名:mysqldb_wrapper-0.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059