什么是数据库,数据库有那些?
# 数据库 : mysql access sql server sqlite
数据库的操做:
# 建立数据库
# 建立表
# 查找
# 插入
# 删除
# 修改
1 sqlit3 数据库 重要函数介绍 2 execute(sql[,parameters]) 执行一条SQL语句 3 cursor(): 返回链接的游标 4 commit():提交当前事务,若是不提交,那么自上次调用 5 commit()方法以后的全部修改都不会真正保存到数据库中 6 rollback()撤销当前事务,将数据库恢复至上次commit()方法后的状态 7 close() 关闭数据库链接
数据库举例
1 import sqlite3 2 conn=sqlite3.connect("example.db")#建立数据库 3 c=conn.cursor()#建立一个数据库的游标 4 #建立表 5 c.execute("create table students(name,sex,age,grade)") #第一次执行就建立表,继续执行会报错 6 #插入数据 7 c.execute("insert into students values('大熊','boy',18,'17级')") 8 c.execute("insert into students values('康复','boy',16,'17级')") 9 for row in c.execute("select * from students order by age "): 10 print(row) 11 print('---------------------') 12 #删除数据 13 # c.execute("delete from students where name='康复'") 14 #数据可修改 15 c.execute("update students set name='静香' where name='大熊'") 16 for row in c.execute("select * from students order by age "): 17 print(row) 18 conn.commit()#数据提交到数据库
练习1:#火车票查询的Python代码 ,网上是保存excel表格 本身尝试修改为用数据库 mysql
2.爬虫的程序,execl表格, 改为用数据库存。