python操作数据库

import pymysql  #调用模块

db = pymysql.connect(user = 'root',password='root',database='test',charset='utf8')  #打开数据库连接

cursor = db.cursor()    #获取操作游标

# sql = "INSERT INTO `person` (`id`, `name`, `sex`, `age`, `number`) VALUES ('6', '吕红红', '女', '35', '365123'), ('8', '范冰冰', '女', '35', '998877');"
sql = "select * from `person` where id in (6,8)"
# sql = "UPDATE `person` SET `age` = '33' WHERE `person`.`id` = 3"
# sql = "UPDATE `person` SET `name` = '李华' WHERE `person`.`number` = 333666"
# sql = "DELETE FROM `person` WHERE `person`.`id` = 4"
# sql ="CREATE TABLE `test`.`student2` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(6) NOT NULL , `sex` VARCHAR(2) NOT NULL , `age` INT(3) NOT NULL , `number` INT(6) NOT NULL , PRIMARY KEY (`id`)) ENGINE = MyISAM"

demo = cursor.execute(sql) #运行SOL语句

lists = cursor.fetchall()   #接收返回的结果


# print(lists)

# for i in lists:
#     for m in i:
#         print(m)

data=db.close() #关闭数据库
print(data)