zoukankan      html  css  js  c++  java
  • mysql与python的交互

    mysql是一种关系型数据库,是为了表示事物与事物之间的关系,本身存于数据库中的内容意义并不大,所以广泛应用于编程语言中,python中九含有与MySQL交互的模块 pymysql

    编程对mysql的操作

    #首先需要引入pymysql模块
    import pymysql
    
    #连接数据库 一般需要几个参数:host  database    user    password    port    charset
    my_conn = pymysql.connect(host="localhost", user="root", password="root", database="laowang", port=3306, charset="utf8")
    
    #开启一个事务
    my_cursor = my_conn.cursor()
    
    #执行SQL语句(增删改通用)
    my_cursor.execute("delete from student where id = 3")
    #(查询)返回一个元组
    content = my_cursor.fetchall()
    print(content)
    
    #提交
    my_conn.commit()
    
    #关闭连接
    my_conn.close()
    
  • 相关阅读:
    【一起来烧脑】读懂HTTP知识体系
    Day16:小前端
    Day15:大前端
    Day14:CSS垂直居中
    Day13:H5+JS+C3
    web学习
    javascript 闭包
    微信小程序微信登录
    微信小程序开源
    mpvue搭建小程序框架
  • 原文地址:https://www.cnblogs.com/Zhao01/p/11994167.html
Copyright © 2011-2022 走看看