mysql 常用查詢語句
查看當前正在運行的sql語句執行最時間:
select * from information_schema.PROCESSLIST
where info is not null order by time desc ;
查看當前有那些表在使用:
show OPEN TABLES where In_use > 0;
查看與innodb事務先關的語句:
SELECT FROM INFORMATION_SCHEMA.INNODB_LOCKS;
SELECT from INFORMATION_SCHEMA.INNODB_TRX;
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
查看當前數據庫的鏈接情況:
SELECT count(*) AS count,USER,db,SUBSTRING_INDEX(HOST, ‘:‘, 1) AS ip FROM information_schema. PROCESSLIST GROUP BY USER,db,ip ORDER BY count desc;
查看數據庫表的碎片情況:
select round(sum(data_length/1024/1024),2) as data_length_MB,
round(sum(index_length/1024/1024),2) as index_length_MB ,
round(sum(data_free/1024/1024),2) as data_free_MB ,table_name
查看死鎖,未提交事物、CHECKPIONT、BUFFER POOL、THREAD等innodb的內部信息:
show engine innodb status;
mysql 常用查詢語句