data = [[1,'admin1','admin1'],[2,'admin2','admin2'],[3,'admin3','admin3']] for i in data: ID = i[0] username = i[1] password = i[2] insert_sql = "insert into demo values(%d,'%s','%s')"%(ID,username,password) cur.execute(insert_sql)
query_sql = 'select * from demo' cur.execute(query_sql) result = cur.fetchall() print(result)
update_sql = "update demo set username='somnus',password='somnus' where id=3" cur.execute(update_sql) cur.execute(query_sql) result = cur.fetchall() print(result)
conn = pymysql.connect(host='localhost',port=3306,user='root',passwd='root',db='pymysql') cur = conn.cursor()
deletecu_sql = "delete from demo where id=1" cur.execute(deletecu_sql) query_sql = 'select * from demo where id=1' if cur.execute(query_sql) == 0: print('column 1 has deleted')
deletetb_sql = "drop table demo" cur.execute(deletetb_sql) query_sql = 'show tables' if cur.execute(query_sql) == 0: print('table has deleted')
deletedb_sql = "drop database pymysql" cur.execute(deletedb_sql) query_sql = 'show databases' cur.execute(query_sql) result = cur.fetchall() if ('pymysql',) notin result: print('database has deleted')