python3 connect to the database mysql, and query

Installation navicat for mysql, Reference: https://www.jianshu.com/p/2494e02caf63

pymysql Import 
ECShop = pymysql.connect ( 'localhost', 'the root', 'the root', 'ECShop') # connect to the database
cus = ecshop.cursor () # Create a cursor object
cus.execute ( "SELECT VERSION ()" ) # sql query execution
#Print (dir (CuS))
DATAS = cus.fetchone () # get a single data
Print (DATAS)
ecshop.close () # close the database
#print (dir (ecshop))

Guess you like

Origin www.cnblogs.com/canglongdao/p/12093973.html