当前位置:Gxlcms > 数据库问题 > python 操作数据库(mysql)

python 操作数据库(mysql)

时间:2021-07-01 10:21:17 帮助过:28人阅读

2、连接数据库后创建一个表

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
cur.execute()

技术分享

3、增加一条数据

     

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()

cur.execute()  #增
cur.close()                             #关闭游标
conn.commit()                           #提交数据(不提交是不能insert的语句不能出现)
conn.close()                            #关闭连接

技术分享

4、删除一条数据

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
cur.execute()                cur.close()
conn.commit()
conn.close()

技术分享

5、修改一条数据

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
cur.execute()     cur.close()
conn.commit()
conn.close()

技术分享

6、查询数据

conn = .connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
ll=cur.execute()
ll

这样只能查出有几条数据,不能查出完整数据

技术分享

调用fetchmang()函数后就可以利用for循环就可以查询出数据

技术分享













python 操作数据库(mysql)

标签:python 操作数据库

人气教程排行