MySQL SHOW STATUS命令介紹
SHOW STATUS提供
MySQL服務的狀態信息,執行這個語句只需要連接到MySQL數據庫的權限。
這些服務狀態信息來源于以下:
① 性能用戶的表。
② INFORMATION_SCHEMA用戶下的GLOBAL_STATUS和SESSION_STATUS表。
MariaDB [test]> desc information_schema.global_status;
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| VARIABLE_NAME | varchar(64) | NO | | | |
| VARIABLE_VALUE | varchar(2048) | NO | | | |
+----------------+---------------+------+-----+---------+-------+
2 rows in set (0.12 sec)
MariaDB [test]> select * from information_schema.global_status where variable_name like 'Com_insert%';
+-------------------+----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+-------------------+----------------+
| COM_INSERT | 106 |
| COM_INSERT_SELECT | 10 |
+-------------------+----------------+
2 rows in set (0.00 sec)
MariaDB [test]> desc information_schema.session_status;
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| VARIABLE_NAME | varchar(64) | NO | | | |
| VARIABLE_VALUE | varchar(2048) | NO | | | |
+----------------+---------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
MariaDB [test]> select * from information_schema.session_status where variable_name like 'Com_insert%';
+-------------------+----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+-------------------+----------------+
| COM_INSERT | 19 |
| COM_INSERT_SELECT | 0 |
+-------------------+----------------+
2 rows in set (0.00 sec)
③ mysqladmin的extended-status命令
[root@localhost 20160630]# /maria/bin/mysqladmin -uroot -p extended-status|grep Com|more
Enter password:
| Com_admin_commands | 0 |
| Com_alter_db | 0 |
| Com_alter_db_upgrade | 0 |
| Com_alter_event | 0 |
| Com_alter_function | 0 |
| Com_alter_procedure | 0 |
| Com_alter_server | 0 |
| Com_alter_table | 40 |
| Com_alter_tablespace | 0 |
| Com_analyze | 3 |
| Com_assign_to_keycache | 0 |
| Com_begin | 0 |
| Com_binlog | 0 |
| Com_call_procedure | 3 |
| Com_change_db | 43 |
| Com_change_master | 0 |
| Com_check | 0 |
| Com_checksum | 0 |
| Com_commit | 0 |
| Com_compound_sql | 0 |
| Com_create_db | 1 |
| Com_create_event | 0 |
| Com_create_function | 0 |
| Com_create_index | 4 |
| Com_create_procedure | 4 |
SHOW STATUS接受GLOBAL或SESSION參數,分別顯示全局或當前連接會話信息,如果不帶參數則顯示的是當前會話的信息。
每次調用SHOW STATUS語句會使用一個臨時表,并會增加Created_tmp_tables全局參數的值。
MariaDB [test]> show global status like 'Created_tmp_tables';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| Created_tmp_tables | 894 |
+--------------------+-------+
1 row in set (0.00 sec)
MariaDB [test]> show global status like 'Created_tmp_tables';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| Created_tmp_tables | 895 |
+--------------------+-------+
1 row in set (0.00 sec)
--常用的統計參數
Com_select 執行SELECT操作的次數
Com_insert 執行INSERT操作的次數
Com_update 執行UPDATE操作的次數
Com_delete 執行DELETE操作的次數
Innodb_rows_read InnoDB存儲引擎SELECT查詢返回的行數
Innodb_rows_inserted InnoDB存儲引擎執行INSERT操作插入的行數
Innodb_rows_updated InnoDB存儲引擎執行UPDATE操作更新的行數
Innodb_rows_deleted InnoDB存儲引擎執行DELETE操作刪除的行數
Connections 連接數
Uptime
服務器工作時間
Slow_queries 慢查詢的次數
MariaDB [test]> show global status like 'Innodb_rows%';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Innodb_rows_deleted | 512 |
| Innodb_rows_inserted | 1662 |
| Innodb_rows_read | 4557 |
| Innodb_rows_updated | 4 |
+----------------------+-------+
4 rows in set (0.00 sec)
MariaDB [test]> show global status like 'Connection%';
+-----------------------------------+-------+
| Variable_name | Value |
+-----------------------------------+-------+
| Connection_errors_accept | 0 |
| Connection_errors_internal | 0 |
| Connection_errors_max_connections | 0 |
| Connection_errors_peer_address | 0 |
| Connection_errors_select | 0 |
| Connection_errors_tcpwrap | 0 |
| Connections | 15 |
+-----------------------------------+-------+
7 rows in set (0.00 sec)
MariaDB [test]> show global status like 'Uptime%';
+---------------------------+---------+
| Variable_name | Value |
+---------------------------+---------+
| Uptime | 1285789 |
| Uptime_since_flush_status | 1285789 |
+---------------------------+---------+
2 rows in set (0.00 sec)
MariaDB [test]> show global status like 'Slow_queries%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries | 0 |
+---------------+-------+
1 row in set (0.00 sec)