python连接mysql数据库 (pymysql)

2018-05-10  本文已影响0人  hello琳123

# -*- 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")

上一篇下一篇

猜你喜欢

热点阅读