美文网首页
python连接mysql数据库 (pymysql)

python连接mysql数据库 (pymysql)

作者: hello琳123 | 来源:发表于2018-05-10 10:10 被阅读0次

    # -*- coding:utf-8 -*-

    import json

    import pymysql

    file = 'F:\\pins_two\\user_xinxi\\pins_two_1.json'

    fp =open(file, 'r')

    str=fp.read()

    ls=eval(str)

    #print(ls[0])

    connent=pymysql.connect(host='localhost',user='root',passwd='123',db='user',charset='utf8')

    cursor=connent.cursor()

    sql="insert into student(age,name) values(55,'limei')"

    try:

        cursor.execute(sql)

        connent.commit()

    except:

        print("Error")

    相关文章

      网友评论

          本文标题:python连接mysql数据库 (pymysql)

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