mysql数据库实例
简单数据查询操作增删改查是数据表操作的重要组成部分,尤其是数据表的查询更是数据库与各类应用交互的频繁操作之一。本文课主要介绍简单数据查询语句。查询语句基本语法查询语句是实现数据查询的SQL语句,用于实...
2024.11.15今天主要分享下关于mysql事务的相关sql,抽空做一下总结,整理如下:
查询正在执行的事务(kill事务的线程ID(trx_mysql_thread_id))select * FROM information_schema.INNODB_TRX;查看正在锁的事务select * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
查看等待锁的事务select * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;查看事务等待状况select r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, r.trx_query waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread, b.trx_query blocking_query FROM information_schema.innodb_lock_waits w INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;查看更具体的事务等待状况select b.trx_state, e.state, e.time, d.state as block_state, d.time as block_time, a.requesting_trx_id, a.requested_lock_id, b.trx_query, b.trx_mysql_thread_id, a.blocking_trx_id, a.blocking_lock_id, c.trx_query as block_trx_query, c.trx_mysql_thread_id as block_trx_mysql_tread_idfrom information_schema.innodb_lock_waits aleft join information_schema.innodb_trx b on a.requesting_trx_id = b.trx_idleft join information_schema.innodb_trx c on a.blocking_trx_id = c.trx_idleft join information_schema.processlist d on c.trx_mysql_thread_id = d.idleft join information_schema.processlist e on b.trx_mysql_thread_id = e.idorder by a.requesting_trx_id;查看未关闭的事务select a.trx_id, a.trx_state, a.trx_started, a.trx_query, b.id, b. user, b. host, b.db, b.command, b.time, b.state, b.info from information_schema.innodb_trx a left join information_schema.processlist b on a.trx_mysql_thread_id = b.id where b.command = ‘sleep‘; 未关闭事务信息selectt1.trx_id,t1.trx_started,t1.trx_mysql_thread_id,t3.event_id,t3.end_event_id,t3.sql_text,concat(‘mysql --login-path=3306 -e ‘‘kill ‘,t1.trx_mysql_thread_id,‘‘‘‘)from information_schema.innodb_trx t1 left join `performance_schema`.threads t2on t1.trx_mysql_thread_id=t2.processlist_idleft join `performance_schema`.events_statements_history t3on t2.thread_id=t3.thread_idwhere t1.trx_started < date_sub(now(), interval 1 minute)and t1.trx_operation_state is nulland t1.trx_query is nullorder by event_id desc;查看某段时间以来未关闭事务select trx_id, trx_started, trx_mysql_thread_id FROM information_schema.innodb_trx WHERE trx_started < date_sub( now( ), INTERVAL 1 MINUTE ) AND trx_operation_state IS NULL AND trx_query IS NULL;觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~
简单数据查询操作增删改查是数据表操作的重要组成部分,尤其是数据表的查询更是数据库与各类应用交互的频繁操作之一。本文课主要介绍简单数据查询语句。查询语句基本语法查询语句是实现数据查询的SQL语句,用于实...
2024.11.15概述前面已经介绍了Oracle如何去获取某用户下的所有表的行数,所以就不介绍了,今天主要分享的是怎么去获取mysql数据库下所有表的数据行数,主要介绍3个方法。1、估算某个数据库下的所有表的记录数可以...
2024.11.12我们都知道现在mysql开源数据库是我们现在小型网站使用较多的免费数据库,我们在创建数据表时容易出现表名出现有问题需要修改,今天在这里教大家利用Sql语句来修改表名的方法:本方法是使用phpMyAdm...
2024.11.15库:show databases;显示所有数据库create database ;创建数据库use ;使用数据库drop 直接删除数据库, 不提醒show tables; 查看当前数据库中的表de...
2024.11.11在MySQL 5.1.7版本中提供了修改数据库名称的SQL语句,语法格式如下:rename DATABASE db_name TO new_db_name但是从 MySQL 5.1.23 版本之后,就...
2024.11.15