Python数据库编程 发表于 2018-09-05 | 分类于 python 字数统计: 157 | 阅读时长 ≈ 1 本文主要介绍python数据库编程相关知识。 1.安装MySQL和MySQL驱动12# yum install gcc python-devel mysql-devel zlib-devel openssl-devel# pip install MySQL-python 2.数据库连接123456789101112131415#!/usr/bin/pytonimport MySQLdbconn = MySQLdb.connect(user='root',passwd='',host='localhost') //连接数据库cur = conn.curson() //创建连接游标conn.select_db('test') //选择数据库cur.execute('create table info(id tinyint)') //执行sql语句cur.execute('insert into info values(1),(2),(3)') //执行sql语句cur.execute('select * from info') //执行sql语句cur.fetchone() //执行sql语句cur.scroll(0,'absolute')cur.fetchmany(3)cur.fetchmany(cur.execute('select * from info'))cur.close()conn.close() ---------------- The End ----------------