美文网首页
python中操作sql的方法

python中操作sql的方法

作者: Ryan96 | 来源:发表于2020-08-25 11:20 被阅读0次
    import pymysql.cursors
    
    #实例化
    connection = pymysql.connect(host='localhost',
                                 port=3306,
                                 user='root',
                                 password='123456',
                                 db='教育',
                                 charset='utf8',
                                 cursorclass = pymysql.cursors.DictCursor)
    
    #光标
    try:
        cursor = connection.cursor()
        sql = """
        SELECT *
        from 5_chengji c 
        JOIN 2_student_info s ON c.mes_StudentID = s.bf_StudentID
        JOIN 6_exam_type e ON c.exam_type = e.EXAM_KIND_ID
        JOIN 1_teacher t on s.cla_id = t.cla_id
        LIMIT 0,100
    
        
        """
        cursor.execute(sql)
        result = cursor.fetchall()#获取所有结果
    except:
        print('报错')
    
    #关闭连接
    cursor.close()
    connection.close()
    
    data = pd.DataFrame(result)
    

    相关文章

      网友评论

          本文标题:python中操作sql的方法

          本文链接:https://www.haomeiwen.com/subject/abiajktx.html