1 """ 2 1.导入模块 3 2.建立连接对象 4 3.创建游标对象 5 4.用游标对象执行sql语句 6 5.对数据进行提交 7 6.关闭游标 8 7.关闭连接对象 9 """ 10 import pymysql; 11 conn = pymysql.connect(host = "localhost" , user = "root" , password = "mysql" , database = "test") 12 cur = conn.cursor() 13 # sql = "insert into account values (3 , 'xiaojing' , 20)" 14 # sql = "delete from account where uid = 2" 15 sql = "update account set balance = 15 where uid = 1 " 16 result = cur.execute(sql) 17 conn.commit() 18 cur.close() 19 conn.close()