1. 程式人生 > >mysql 常用查詢語句

mysql 常用查詢語句

常用 bstr substring status 當前 substr list not null sch

  • 查看當前正在運行的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

    from information_schema.tables where TABLE_SCHEMA= ‘db_name‘ group by table_name order by 3 desc;

  • 查看死鎖,未提交事物、CHECKPIONT、BUFFER POOL、THREAD等innodb的內部信息:
    show engine innodb status;

  • 後續不斷更新。。。。。。。
  • mysql 常用查詢語句