一、MySql连接长时间未操作,连接丢失
def test_conn(self):
try:
self.conn.ping()
except:
self.conn = pymysql.connect(host=self.host, port=self.port, user=self.user, password=self.password,
db=self.db_name)
二、删除重复数据,保留最后一条记录
delete from users where id not in (
select t.max_id from
(select max(id) as max_id from users group by identity_id,name) as t
);
三、死锁
1、查看当前运行的事务,这点在变更表结构之前必须要查看
select * from information_schema.innodb_trx;
2、查看当前运行的事务的账户和事务开始的时间,及其事务语句
select
a.id,a.user,a.host,b.trx_started,b.trx_query
from information_schema.processlist a right outer join information_schema.innodb_trx b
on a.id = b.trx_mysql_thread_id;
3、删掉死锁的事务
select * from information_schema.innodb_trx
kill 953