一、关于数据库加锁主要分为几类
1.原生sql
1.开启事物
begin; select * from host for update; commit;
注意:INNODB支持表锁和行锁,MyISAM只支持表锁
2.pymysql
pymysql自带事物
cursor.execute('select * from host for update')
3.sqlalchemy
db.session.query(model.hosts).filter_by(id=did).with_for_update().first()
4.django的orm
from django.db import transcation
with transcation.atomic():
Test.objects.filter(id=1).select_for_update()