Operation of the python MySQL module pymysql

Import pymysql # PIP install pymysql 
db = pymysql.connect ( ' localhost ' , ' root ' , ' 123456 ' , ' day040 ' ) 
the Cursor = db.cursor ()   # create a cursor 

book_list = [ " learn python from the beginning to give up | alex | people's University Press | 50 | 2018-7-1 " ,
            " learn from the beginning to give up mysql | egon | Machinery industry Press | 60 | 2018-6-3 " ,
            " learn from the beginning to give up html | alex | Machinery Press | 20 | 2018-4-1 " ,
            "Learn css from the beginning to give up | wusir | Machinery Industry Press | 120 | 2018-5-2" ,
            " Learn from the beginning to give up js | wusir | Machinery Industry Press | 100 | 2018-7-30 " ] 

# for Row in book_list: 
#      Book = row.split (" | ") 
#      Book [-2] = a float (Book [-2]) 
#      Book = tuple (Book) 
#      SQL = F "INSERT INTO Book2 (b_name, b_author, b_press, per B_PERIOD, the publish_date) Book values {};" 
#      the cursor.execute (SQL) statements executed # only in memory to perform 
#      the db.commit () # submitted to the database changes (additions and deletions to be submitted to complete) 



SQL = ' the SELECT * from Book2 ' 
cursor.execute (SQL) 


# get a: fetchone () 
# Re = the Cursor. fetchone () 
# Print (Re)


# 获取部分fetchmany(n)
# results=cursor.fetchmany(3)
# print(results)


# 获取所有fetchall()
results=cursor.fetchall()
for row in results:
    for i in row:
        print(i,end='')
    print()


db.close()

 

Guess you like

Origin www.cnblogs.com/open-yang/p/11414907.html