python 连接操作mysql数据库
时间:2021-07-01 10:21:17
帮助过:24人阅读
数据库连接对象:connection
数据库交互对象:cursor
- sql=‘select * from user ‘
- cursor.execute(sql)
- rs=cursor.rowcount
- print rs
- rs=cursor.fetchone()
- print rs
- rs=cursor.fetchmany(3)
- print rs
- rs=cursor.fetchall()
- print rs
- for row in rs:
- print ‘userID=%s username=%s‘% row
- cursor.close()
- conn.close()
python 连接操作mysql数据库
标签:sql查询 tar cut import select fetchall 交互 回滚事务 游标