Http://www.tuicool.com/articles/yqayEv
1 ImportPymysql2conn = Pymysql.connect (host='localhost', port=3306,user='Root', passwd='Root', db='deliveryaddress', charset='UTF8')3Cur =conn.cursor ()4Cur.execute ("INSERT into ' Provincecitycountytown ' VALUES (' 3 ', ' 0 ', ' Shanghai ')")5Conn.commit ()#here is submitted with conn, very confusing, why not cur submit it? I have not found an example of Baidu,6 cur.close ()7Conn.close ()
Try: #get a database connection, note if the UTF-8 type, you need to make a databaseconn = Pymysql.connect (host=host,user=user,passwd=passwd,db=db,port=port,charset=charset) Cur= Conn.cursor ()#gets a cursorCur.execute ('SELECT * from user') Data=Cur.fetchall () forDinchData:#note the int type needs to be escaped with the STR function Print("ID:"+str (D[0]) +'Name:'+d[1]) Cur.close () conn.close ()except: Print("DB except")
API documentation connection for database operations: http://legacy.python.org/dev/peps/pep-0249/
How to connect to MySQL using Python3.4