MySQL库表状态查询
一. 查看库的各链接状态
对于一个mysql连接或者一个线程,任何时刻都有一个状态,表示其当前正在做什么。一般使用show full processlist查看。
+---------+-------------+-------------------+------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+-------------+-------------------+------+---------+------+-------+-----------------------+
| 2547225 | operator@RR | 10.3.18.205:60253 | fb | Query | 0 | NULL | show full processlist |
| 2548100 | operator@RR | 10.4.19.83:51754 | fb | Sleep | 1 | | NULL |
| 2548101 | operator@RR | 10.4.19.83:53661 | fb | Sleep | 1 | | NULL |
| 2548102 | operator@RR | 10.4.19.83:45808 | fb | Sleep | 1 | | NULL |
| 2548103 | operator@RR | 10.4.19.83:58881 | fb | Sleep | 1 | | NULL |
| 2548104 | operator@RR | 10.4.19.83:33521 | fb | Sleep | 1 | | NULL |
+---------+-------------+-------------------+------+---------+------+-------+-----------------------+
show full processlist
二. 查看存储引擎
2.1 查看当前库支持的存储引擎
保存在information_schema.ENGINES表里。
SHOW ENGINES
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
结果
2.2 查看某存储引擎的状态
SHOW ENGINE INNODB STATUS
=====================================
2016-01-15 10:12:44 7f4a4c4b6700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 38 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 1 srv_active, 0 srv_shutdown, 172619 srv_idle
srv_master_thread log flush and writes: 172620
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 3
OS WAIT ARRAY INFO: signal count 3
Mutex spin waits 40, rounds 47, OS waits 1
RW-shared spins 2, rounds 60, OS waits 2
RW-excl spins 0, rounds 0, OS waits 0
Spin rounds per wait: 1.18 mutex, 30.00 RW-shared, 0.00 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 1799
Purge done for trx's n:o < 0 undo n:o < 0 state: running but idle
History list length 0
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 152, OS thread handle 0x7f4a4c4b6700, query id 137 192.168.122.45 adu_w init
show engine innodb status
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (read thread)
I/O thread 7 state: waiting for completed aio requests (read thread)
I/O thread 8 state: waiting for completed aio requests (read thread)
I/O thread 9 state: waiting for completed aio requests (read thread)
I/O thread 10 state: waiting for completed aio requests (write thread)
I/O thread 11 state: waiting for completed aio requests (write thread)
I/O thread 12 state: waiting for completed aio requests (write thread)
I/O thread 13 state: waiting for completed aio requests (write thread)
I/O thread 14 state: waiting for completed aio requests (write thread)
I/O thread 15 state: waiting for completed aio requests (write thread)
I/O thread 16 state: waiting for completed aio requests (write thread)
I/O thread 17 state: waiting for completed aio requests (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0, 0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0, 0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
190 OS file reads, 5 OS file writes, 5 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 1626012
Log flushed up to 1626012
Pages flushed up to 1626012
Last checkpoint at 1626012
Max checkpoint age 867604194
Checkpoint age target 840491563
Modified age 0
Checkpoint age 0
0 pending log writes, 0 pending chkp writes
8 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 1098907648; in additional pool allocated 0
Total memory allocated by read views 88
Internal hash tables (constant factor + variable factor)
Adaptive hash index 18926128 (18921928 + 4200)
Page hash 139112 (buffer pool 0 only)
Dictionary cache 4487029 (4426736 + 60293)
File system 815920 (812272 + 3648)
Lock system 2657536 (2657176 + 360)
Recovery system 0 (0 + 0)
Dictionary memory allocated 60293
Buffer pool size 65528
Buffer pool size, bytes 1073610752
Free buffers 65354
Database pages 174
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 174, created 0, written 1
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 174, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
----------------------
INDIVIDUAL BUFFER POOL INFO
----------------------
---BUFFER POOL 0
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8159
Database pages 32
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 32, created 0, written 1
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 32, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 1
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8187
Database pages 4
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 4, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 4, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 2
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8187
Database pages 4
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 4, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 4, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 3
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8123
Database pages 68
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 68, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 68, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 4
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8129
Database pages 62
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 62, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 62, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 5
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8187
Database pages 4
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 4, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 4, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 6
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8191
Database pages 0
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 0, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 0, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 7
Buffer pool size 8191
Buffer pool size, bytes 134201344
Free buffers 8191
Database pages 0
Old database pages 0
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 0, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 0, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
0 RW transactions active inside InnoDB
0 RO transactions active inside InnoDB
0 out of 1000 descriptors used
Main thread process no. 3572, id 139955545581312, state: sleeping
Number of rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
结果
二. 查看表状态
2.1 单表详情
数据库各表的信息都保存在INFORMATION_SCHEMA-->TABLES表里。可以直接在此表查询也可以通过SHOW TABLE STATUS命令来查询。
SHOW TABLE STATUS LIKE 'user'\G;
结果:
*************************** 1. row ***************************
Name: user(表名)
Engine: InnoDB(存储引擎)
Version: 10
Row_format: Compact(行的格式,是否固定或压缩)
Rows: 4(行数,对于MyISAM该值是精确的,但对于InnoDB该值是估计值)
Avg_row_length: 4096(平均每行的字节数)
Data_length: 16384(表数据总的字节数)
Max_data_length: 0(表数据的最大容量,和存储引擎有关)
Index_length: 0(索引的大小B)
Data_free: 7340032(对于MyISAM表示已分配但没有使用的空间)
Auto_increment: 5(下一个AUTO_INCREMENT值)
Create_time: 2014-06-17 16:45:53(表的创建时间)
Update_time: NULL(表数据的最后修改时间)
Check_time: NULL(使用CHECK TABLE或myisamchk检查表的时间)
Collation: utf8_bin(表的默认字符集和字符列排序规则)
Checksum: NULL(整个表的实时检验和)
Create_options: (创建表时指定的其他选项)
Comment:
1 row in set (0.00 sec)
- *_bin: 表示的是binary case sensitive collation,也就是说是区分大小写的
- *_cs: case sensitive collation,区分大小写
- *_ci: case insensitive collation,不区分大小写
2.2 各表的占用空间大小
SELECT
CONCAT(table_schema,'.',table_name) AS 'Table Name',
table_rows AS 'Number of Rows',
CONCAT(ROUND(data_length/(1024*1024),3),' MB') AS 'Data Size',
CONCAT(ROUND(index_length/(1024*1024),3),' MB') AS 'Index Size',
CONCAT(ROUND((data_length+index_length)/(1024*1024),3),' MB') AS 'Total Size'
FROM
information_schema.TABLES
WHERE
table_schema = 'db_name' AND table_name = 'table_name';
三. 查看执行计划
EXPLAIN sql...
explain显示了mysql如何使用索引来处理select语句以及连接表。可以帮助选择更好的索引和写出更优化的查询语句。
EXPLAIN SELECT id FROM user WHERE id=1 \G;
结果:
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: user
type: const
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: const
rows: 1
Extra: Using index
1 row in set (0.02 sec)
列名 | 类型 | 解释 |
---|---|---|
id | SELECT语句的ID编号,优先执行编号较大的查询,如果编号相同,则从上向下执行 | |
select_type | SIMPLE | 一条没有UNION或子查询部分的SELECT语句 |
PIMARY | 最外层或最左侧的SELECT语句 | |
UNION | UNION语句里的第二条或最后一条SELECT语句 | |
DEPENDENT UNION | 和UNION类型的含义相似,但需要依赖于某个外层查询 | |
UNION RESULT | 一条UNION语句的结果 | |
SUBQUERY | 子查询中的第一个SELECT子句 | |
DEPENDENT SUBQUERY | 和SUBQUERY类型的含义相似,但需要依赖于某个外层查询 | |
DERIVED | FROM子句里的子查询 | |
table | t1 | 各输出行里的信息是关于哪个数据表的 |
Partitions | NULL | 将要使用的分区.只有EXPLAIN PARTITIONS ...语句才会显示这一列.非分区表显示为NULL |
type | 联接操作的类型,性能由好到差依次如下 | |
system | 表中仅有一行 | |
const | 单表中最多有一个匹配行 | |
eq_ref | 联接查询中,对于前表的每一行,在此表中只查询一条记录,使用了PRIMARY或UNIQUE | |
ref | 联接查询中,对于前表的每一行,在此表中只查询一条记录,使用了INDEX | |
ref_or_null | 联接查询中,对于前表的每一行,在此表中只查询一条记录,使用了INDEX,但是条件中有NULL值查询 | |
index_merge | 多个索引合并 | |
unique_subquery | 举例说明: value IN (SELECT primary_key FROM single_table WHERE some_expr) | |
index_subquery | 举例说明: value IN (SELECT key_column FROM single_table WHERE some_expr) | |
range | 只检索给定范围的行,包括如下操作符: =, <>, >, >=, <, <=, IS NULL, <=>, BETWEEN, or IN() | |
index | 扫描索引树(略比ALL快,因为索引文件通常比数据文件小) | |
ALL | 前表的每一行数据都要跟此表匹配,全表扫描 | |
possible_keys | NULL | MySQL认为在可能会用到的索引.NULL表示没有找到索引 |
key | NULL | 检索时,实际用到的索引名称.如果用了index_merge联接类型,此时会列出多个索引名称,NULL表示没有找到索引 |
key_len | NULL | 实际使用的索引的长度.如果是复合索引,那么只显示使用的最左前缀的大小 |
ref | NULL | MySQL用来与索引值比较的值, 如果是单词const或者???,则表示比较对象是一个常数.如果是某个数据列的名称,则表示比较操作是逐个数据列进行的.NULL表示没有使用索引 |
rows | MySQL为完成查询而需要在数据表里检查的行数的估算值.这个输出列里所有的值的乘积就是必须检查的数据行的各种可能组合的估算值 | |
Extra | Using filesort | 需要将索引值写到文件中并且排序,这样按顺序检索相关数据行 |
Using index | MySQL可以不必检查数据文件, 只使用索引信息就能检索数据表信息 | |
Using temporary | 在使用 GROUP BY 或 ORDER BY 时,需要创建临时表,保存中间结果集 | |
Using where | 利用SELECT语句中的WHERE子句里的条件进行检索操作 |
MySQL库表状态查询的更多相关文章
- Mysql 库表操作初识
Mysql 库表操作初识 终端登录mysql 这里只演示win下, cmd 终端. 至于怎么在win下, linux, mac安装, 感觉这是一个入门级的百度搜索问题, 安装都搞不定, 确实有点尴尬, ...
- python Mysql 库表
Mysql 库表 创建 学生信息库表 学生成绩 库表
- mysql库表优化实例
一.SQL优化 1.优化SQL一般步骤 1.1 查看SQL执行频率 SHOW STATUS LIKE 'Com_%'; Com_select:执行SELECT操作的次数,一次查询累加1.其他类似 以下 ...
- python 存储引擎 mysql(库,表, 行) 单表多表操作 (foreign key) sql_mode pymysql模块讲解
##################总结############### mysql 常用数据类型 整型:tinyint int(42亿条左右) bigint 小数:float double dec ...
- MySQL库表详细操作
昨天我们初始了MySQL,今天我们先从库表方面详细说一下具体操作 一.库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset utf8; 1.2 数据库命名规则 ...
- MySQL库表设计小技巧
前言: 在我们项目开发中,数据库及表的设计可以说是非常重要,我遇到过很多库表设计比较杂乱的项目,像表名.字段名命名混乱.字段类型设计混乱等等,此类数据库后续极难维护与拓展.我一直相信只有优秀的库表设计 ...
- 【连接查询】mySql多表连接查询与union与union all用法
1.准备两个表 表a: 结构: mysql> desc a; +-------+-------------+------+-----+---------+-------+ | Field | T ...
- mysql数据库表的查询操作-总结
转自:https://www.cnblogs.com/whgk/p/6149009.html 序言 1.MySQL表操作(创建表,查询表结构,更改表字段等), 2.MySQL的数据类型(CHAR.VA ...
- MySQL多表数据查询(DQL)
数据准备: /* ------------------------------------创建班级表------------------------------------ */ CREATE TAB ...
随机推荐
- logstash 发送慢页面到zabbix告警
input { file { type => "zj_frontend_access" path => ["/data01/applog_backup/zjz ...
- 【转】Java如何克隆集合——深度拷贝ArrayList和HashSet
原文网址:http://blog.csdn.net/cool_sti/article/details/21658521 原英文链接:http://javarevisited.blogspot.hk/2 ...
- bzoj1003[ZJOI2006]物流运输trans
1003: [ZJOI2006]物流运输trans Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常 ...
- CoreData Multiple Context性能分析-读书笔记
From: http://floriankugler.com/blog/2013/4/29/concurrent-core-data-stack-performance-shootout http: ...
- XPath详解
xPath技术 1 引入 问题:当使用dom4j查询比较深的层次结构的节点(标签,属性,文本),比较麻烦!!! 2 xPath作用 主要是用于快速获取所需的节点对象. 3 在dom4j中如何使用 ...
- android中使用哪种方式解析XML比較好
SAX是一个用于处理XML事件驱动的"推"模型. 长处是一种解析速度快而且占用内存少的xml解析器,它须要哪些数据再载入和解析哪些内容. 缺点是它不会记录标签的关系.而要让你的应用 ...
- maven pom.xml具体解释(整理)
pom作为项目对象模型. 通过xml表示maven项目,使用pom.xml来实现.主要描写叙述了项目:包含配置文件.开发人员须要遵循的规则,缺陷管理系统.组织和licenses,项目的url,项目的依 ...
- spring-data-mongodb必须了解的操作
http://docs.spring.io/spring-data/data-mongo/docs/1.0.0.M5/api/org/springframework/data/mongodb/core ...
- 【POJ2114】Boatherds 树分而治之
做广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog. ...
- 畅通project
原文请訪问:p=174">http://xiaoshig.sinaapp.com/?p=174 畅通project Time Limit:2000MS Memory Limit ...