python-devel mysql-devel
在python中简单的使用
1、连接数据库
db = MySQLdb.connect('127.0.0.1','root','root','database...或者
db = MySQLdb.connect(host='127.0.0.1',port='3307',user='root',passwd='root',db='database')
#一般来说,在代码中放置密码并不是一个好主意...= 'select * from test_table WHERE id = %s'
# 执行sql语句 .execute()
cursor.execute(sql_sel,(cid,))
# 返回值....fetchone() 返回单元组类型
cursor.fetchone()
(值1, 值2, 值3...)
4、如果您想要更多行,可以使用 .fetchmany(n) 或 .fetchall()。...这两个方法都返回一系列行,如果没有更多行,则返回一个空序列。
如果使用奇怪的游标类,则行本身可能不是元组。
请注意,与上面相反, 当没有更多行要提取时 c.fetchone() 返回 None。