自带的库:mysql、information_schema、performance_schema、sys。

information_schema【内存表,没有文件】

TABLES表

记录所有表的元数据,可以用来扫描那个表不是InnoDB表。
image.png

STATISTICS

查看索引cardinality

索引相关

巡检没有主键的表

  1. SELECT
  2. *
  3. FROM
  4. information_schema.TABLES t
  5. LEFT JOIN
  6. information_schema.STATISTICS s ON t.table_schema = s.table_schema
  7. AND t.table_name = s.table_name
  8. AND s.index_name = 'PRIMARY'
  9. WHERE
  10. t.table_schema NOT IN ('mysql' , 'performance_schema',
  11. 'information_schema',
  12. 'sys')
  13. AND table_type = 'BASE TABLE'
  14. AND s.index_name IS NULL;


PROCESSLIST

实时慢查询

MySQL监控

sys[5.7]

5.6有开源sql安装sys库。
sys其中包含大量视图,视图数据来源就是information_schema和performance_schema

statement系列

image.png

schema_index_statistics

索引统计

schema_redundant_indexes:冗余索引

image.png

schema_unused_indexes:没有使用的索引

索引相关
设置索引不可见(代替删除):image.png

innodb_lock_waits:锁等待

检查阻塞死锁

performance_schema

performance_schema全方位介绍
performance_schema在5.6及其之前的版本中,默认没有启用,从5.7及其之后的版本才修改为默认启用

variables_by_thread:各线程的变量

image.png

查看各线程的隔离级别

image.png

threads

select * from threads;

查看mysql线程占用资源高[5.7才有thread_os_id]

image.png

  • thread_os_id:操作系统top -H显示的线程id
  • PROCESSLIST_ID:通过show processlist 查看线程具体操作

image.png

mysql库

user

select host,user,password from mysql.user;
5.7之前password,之后authentication_string