"Using Python for Database pruning"
The code is as follows:
From pymysql Import *
def main ():
# 1. Create a Connection connection
conn = connect (host= ' localhost ', port=3306,database= ' Jing_dong ', user= ' root ', password= ' MySQL ', charset= ' UTF8 ')
# 2. Get Cursor Object
CS1 = Conn.cursor ()
# executes the INSERT statement and returns the number of rows affected: Add a piece of data
#Cursor对象. Execute (Database operations)
# Add Item "hard drive" count to receive the number of rows affected
Count = Cs1.execute (' INSERT into goods_cates (name) VALUES ("hdd") ')
#打印受影响的行数
Print (count)
#增加物品 "Disc"
Count = Cs1.execute (' INSERT into goods_cates (name) VALUES ("disc") ')
Print (count)
# Update data table
# count = Cs1.execute (' Update goods_cates set name= ' mechanical hard drive ' where name= ' hard disk ')
# Delete Items
# count = Cs1.execute (' Delete from goods_cates where id=6 ')
# Before the action is committed, if it has been executed many times before execute, then all commit
Conn.commit ()
# Close Cursor Object
Cs1.close ()
# Close Connection Object
Conn.close ()
if __name__ = = ' __main__ ':
Main ()
Python operation MySQL