数据库
首页 > 数据库> > python 操作mysql

python 操作mysql

作者:互联网

import pymysql

dbinfo={

  "host":"192.16.8.x",

  "post":3306,

  "user":"root",

  "password":"xxxx",

  "database":"xxx"

}

 

import pymysql

class DBopera:
def __init__(self,dbinfo=dbinfo):
self.conn = pymysql.connect(**dbinfo)
self.cur = self.conn.cursor()
def dbselect(self,sql):
self.cur.execute(sql)
result = self.cur.fetchall()
print(result)
def dbcommit(self,sql):
self.cur.execute(sql)
self.conn.commit()
def dbclose(self):
self.cur.close()
self.conn.close()

 

 


 

标签:cur,python,self,sql,dbinfo,def,mysql,操作,conn
来源: https://www.cnblogs.com/wuhhaa/p/16600439.html