一、使用pymysql
1、安装
pip install pymysql
2、使用
1 | import pymysql |
二、新增
1 | create_data = [('xxx', 18)] |
三、删除
1 | delete_sql = "delete from table where name='{}'" |
四、修改
1 | update_sql = "update table set name=(%s) where age='18' and gender='male'" |
五、查询
1 | query_sql = "select * from table where name='name'" |
六、操作失败回滚
1 | try: |
七、关闭链接
1 | cursor.close() |