MySQLdb库

import MySQLdb

 

简介

提供mysql的基本操作(包括建表,读取表数据,插入数据到表)

 

数据库操作基本步骤

 

python的MySQLdb库基本使用介绍
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import MySQLdb

if __name__ == "__main__":
    # 打开数据库连接
    db = MySQLdb.connect("localhost", "root", "root", "iquota", charset='utf8')

    # 使用cursor()方法获取操作游标
    cursor = db.cursor()

    # 查看表
    sql_cmd="select * from app;"

    cursor.execute(sql_cmd)
    data = cursor.fetchone()
    data_all = cursor.fetchall()

    # 关闭数据库连接
    db.close()

    # 读取一行
    print data
    # 读取全部内容
    print data_all
mysql基本读取举例

相关文章:

  • 2021-07-18
  • 2021-09-11
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-05-23
猜你喜欢
  • 2021-10-19
  • 2021-10-19
  • 2021-11-21
  • 2023-01-15
  • 2021-11-12
  • 2021-08-07
相关资源
相似解决方案