MySQL 5.7 performance_schema庫和sys庫常用SQL
performance_schema庫常用SQL:
檢視沒有主鍵的表:
SELECT DISTINCT t.table_schema, t.table_name
FROM information_schema.tables AS t
LEFT JOIN information_schema.columns AS c ON t.table_schema = c.table_schema
AND t.table_name = c.table_name AND c.column_key = "PRI"
WHERE t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema')
AND c.table_name IS NULL AND t.table_type != 'VIEW';
例如:
mysql> SELECT DISTINCT t.table_schema, t.table_name
-> FROM information_schema.tables AS t
-> LEFT JOIN information_schema.columns AS c ON t.table_schema = c.table_schema
AND t.table_name = c.table_name AND c.column_key = "PRI"
-> WHERE t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema')
-> AND c.table_name IS NULL AND t.table_type != 'VIEW';
+--------------+---------------------------+
| table_schema | table_name |
+--------------+---------------------------+
| S85 | dsf |
| test | innodb_lock_monitor |
| test | innodb_monitor |
| test | innodb_table_monitor |
| test | innodb_tablespace_monitor |
| zhwp102 | t_orgpriority |
| zhwp102 | t_task_ext |
| zhwp102 | t_web_common |
| zhwp111 | t_orgpriority |
| zhwp111 | t_task_ext |
| zhwp111 | t_web_common |
| zhwp111 | t_weibo |
| zhwp_prod | t_orgpriority |
| zhwp_prod | t_task_ext |
| zhwp_prod | t_web_common |
| zhwp_prod | t_weibo |
| zhwpzj111 | t_orgpriority |
| zhwpzj111 | t_task_ext |
| zhwpzj111 | t_web_common |
| zhwpzj111 | t_weibo |
+--------------+---------------------------+
20 rows in set (1 min 27.55 sec)
沒有主鍵:
mysql> desc S85.dsf;
+------------+----------------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+-------------------+-------+
| sourceDay | date | YES | | NULL | |
| sourceTime | datetime | NO | | CURRENT_TIMESTAMP | |
| affections | smallint(5) unsigned | NO | | 1 | |
+------------+----------------------+------+-----+-------------------+-------+
3 rows in set (0.00 sec)
檢視是誰建立的臨時表
SELECT user, host, event_name, count_star AS cnt, sum_created_tmp_disk_tables AS tmp_disk_tables,
sum_created_tmp_tables AS tmp_tables
FROM performance_schema.events_statements_summary_by_account_by_event_name
WHERE sum_created_tmp_disk_tables > 0
OR sum_created_tmp_tables > 0 ;
沒有正確關閉資料庫連線的使用者
SELECT ess.user, ess.host
, (a.total_connections - a.current_connections) - ess.count_star as not_closed
, ((a.total_connections - a.current_connections) - ess.count_star) * 100 /
(a.total_connections - a.current_connections) as pct_not_closed
FROM performance_schema.events_statements_summary_by_account_by_event_name ess
JOIN performance_schema.accounts a on (ess.user = a.user and ess.host = a.host)
WHERE ess.event_name = 'statement/com/quit'
AND (a.total_connections - a.current_connections) > ess.count_star ;
DDL後設資料鎖跟蹤
1.開啟跟蹤:
UPDATE performance_schema.setup_instruments SET ENABLED = 'YES' WHERE
NAME = 'wait/lock/metadata/sql/mdl';
UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE
NAME = 'global_instrumentation';
2.查詢metadata lock:
select * from performance_schema.metadata_locks;
select * from performance_schema.metadata_locks where LOCK_STATUS like 'PENDING%';
select ID from information_schema.processlist where Info like '%20190416%' \G
SELECT OBJECT_TYPE,OBJECT_SCHEMA,OBJECT_NAME,LOCK_STATUS,processlist_id
FROM performance_schema.metadata_locks mdl
INNER JOIN performance_schema.threads thd ON mdl.owner_thread_id = thd.thread_id
WHERE processlist_id <> @@pseudo_thread_id;
3.關閉跟蹤:
UPDATE performance_schema.setup_instruments SET ENABLED = 'NO' WHERE
NAME = 'wait/lock/metadata/sql/mdl';
DDL執行進度跟蹤
1.開啟跟蹤:
UPDATE performance_schema.setup_instruments SET ENABLED = 'YES' WHERE NAME LIKE 'stage/innodb/alter%';
UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME LIKE '%stages%';
2.檢視DDL執行進度:
SELECT EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED,(WORK_COMPLETED/WORK_ESTIMATED)*100
as COMPLETED FROM performance_schema.events_stages_current;
sys庫常用SQL:
檢視錶訪問量
select table_schema,table_name,sum(io_read_requests+io_write_requests) io from sys.schema_table_statistics
group by table_schema,table_name order by io desc limit 10;
檢視資料庫連線情況
select * from sys.processlist \G
select * from sys.session limit 10 \G
select * from sys.x$processlist \G
select * from sys.x$session \G
檢視冗餘索引
select table_schema,table_name,redundant_index_name,redundant_index_columns,dominant_index_name,
dominant_index_columns from sys.schema_redundant_indexes;
檢視未使用索引
select * from sys.schema_unused_indexes;
表自增ID監控
select * from sys.schema_auto_increment_columns limit 10;
檢視實際消耗磁碟IO的檔案
select file,avg_read+avg_write as avg_io from sys.io_global_by_file_by_bytes order by avg_io desc limit 10;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2641633/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL sys庫常用SQL彙總大全MySql
- mysql 5.7 sys資料庫初探MySql資料庫
- MySQL預設資料庫之performance_schema庫MySql資料庫ORM
- 1.4 資料庫和常用SQL語句(正文)——MySQL資料庫命令和SQL語句資料庫MySql
- mysql 5.7後使用sys資料庫下的表查詢資料庫效能狀況MySql資料庫
- MySQL預設資料庫之sys庫MySql資料庫
- MySQL 5.7 主庫崩潰切備庫MySql
- 遷移MySQL 5.7資料庫MySql資料庫
- MySQL資料庫:7、SQL常用查詢語句MySql資料庫
- MySQL 5.7主從新增新從庫MySql
- shell監控mysql 5.7資料庫MySql資料庫
- [資料庫]50道經典SQL練習題,使用MySQL5.7解答資料庫MySql
- Homestead 中 sys 資料庫 和 #MySQL50#lost+found 資料庫 是幹嘛的?資料庫MySql
- MySQL5.7: sql script demoMySql
- MySQL資料庫常用操作MySql資料庫
- Mysql 常用資料庫命令MySql資料庫
- 資料庫常用的sql語句大全--sql資料庫SQL
- Sql Server 資料庫學習-常用資料庫 物件SQLServer資料庫物件
- 資料庫常用操作SQL語句資料庫SQL
- MYSQL資料庫------SQL優化MySql資料庫優化
- MySQL 5.7從庫system lock執行緒解釋MySql執行緒
- phpStudy2018 升級資料庫 MySQL5.7PHP資料庫MySql
- MySQL資料庫SYS CPU高的可能性分析MySql資料庫
- mysql 常用sqlMySql
- 【MySQL資料庫】MySQL5.7安裝與配置、視覺化工具安裝和破解MySql資料庫視覺化
- Python常用庫和小眾庫推薦Python
- 【資料庫】mysql5.6升級至5.7(物理方式)資料庫MySql
- MySQL 資料庫與 SQL 優化MySql資料庫優化
- (二)oralce資料庫中sys_guid()和newid()資料庫GUI
- MySQL 5.7定位消耗CPU高的SQLMySql
- MySQL資料庫之mysql5.7基礎 檢視一個資料庫中的所有表MySql資料庫
- MYSQL資料庫常用基本設定MySql資料庫
- 【資料庫學習】資料庫平臺:mysql,sql server資料庫MySqlServer
- 【MYSQL】Mysql常用檢查sqlMySql
- 工作中常用的oracle資料庫sqlOracle資料庫SQL
- 資料庫常用的sql語句彙總資料庫SQL
- 破解 MySQL5.7 資料庫的 root 登入密碼MySql資料庫密碼
- SQL建立資料庫和表SQL資料庫