自带的库:mysql、information_schema、performance_schema、sys。
information_schema【内存表,没有文件】
TABLES表
STATISTICS
查看索引cardinality
巡检没有主键的表
SELECT
*
FROM
information_schema.TABLES t
LEFT JOIN
information_schema.STATISTICS s ON t.table_schema = s.table_schema
AND t.table_name = s.table_name
AND s.index_name = 'PRIMARY'
WHERE
t.table_schema NOT IN ('mysql' , 'performance_schema',
'information_schema',
'sys')
AND table_type = 'BASE TABLE'
AND s.index_name IS NULL;
PROCESSLIST
实时慢查询
sys[5.7]
5.6有开源sql安装sys库。
sys其中包含大量视图,视图数据来源就是information_schema和performance_schema
statement系列
- full table scans 加索引
- sorting多的 加索引
sys.statement_analysis【统计,而不是记录所有单条log】
记录sql的执行情况,可代替慢查询日志
MySQL SYS数据库说明_王仲肖的博客-CSDN博客
schema_index_statistics
schema_redundant_indexes:冗余索引
schema_unused_indexes:没有使用的索引
索引相关
设置索引不可见(代替删除):
innodb_lock_waits:锁等待
performance_schema
performance_schema全方位介绍
performance_schema在5.6及其之前的版本中,默认没有启用,从5.7及其之后的版本才修改为默认启用
variables_by_thread:各线程的变量
查看各线程的隔离级别
threads
查看mysql线程占用资源高[5.7才有thread_os_id]
- thread_os_id:操作系统top -H显示的线程id
- PROCESSLIST_ID:通过show processlist 查看线程具体操作
mysql库
user
select host,user,password from mysql.user;
5.7之前password,之后authentication_string