select p.id,p.user,p.host,p.db,p.command,p.time,i.trx_state,i.trx_started,p.info from information_schema.processlist p,information_schema.innodb_trx i where p.id=i.trx_mysql_thread_id;
2.查看当前连接,并且能够知晓连接数
1
select SUBSTRING_INDEX(host,‘:‘,1) asip , count(*) from information_schema.processlist group by ip;
3.查看一个表的大小
1
select concat(round(sum(DATA_LENGTH/1024/1024),2),‘M‘) from information_schema.tables where table_schema=‘数据库名‘ AND table_name=‘表名‘;
4.查看某个数据库所有表的大小
1
select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),‘M‘) from information_schema.tables where table_schema=‘t1‘ group by table_name;
from information_schema.tables where table_schema=‘db_name‘ group by table_name;
2.查看各个数据库的数据大小
1
select TABLE_SCHEMA, concat(round(sum(data_length)/1024/1024,2),‘ MB‘) asdata_size from information_schema.tables group by table_schema;
3.查看实例有没有主键
1
2
3
4
select table_schema,table_name from information_schema.tables
where (table_schema,table_name)
not in(select distinct table_schema,table_name from information_schema.STATISTICS where INDEX_NAME=‘PRIMARY‘ )
andtable_schema not in ( ‘sys‘,‘mysql‘,‘information_schema‘,‘performance_schema‘);
4.查看实例中哪些字段可以为null
1
select TABLE_SCHEMA,TABLE_NAME from COLUMNS where IS_NULLABLE=‘YES‘ andTABLE_SCHEMA not in (‘information_schema‘,‘performance_schema‘,‘mysql‘, ‘sys‘)\G
5.查看实例中有哪些存储过程和函数
1
2
3
4
5
6
7
8
#存储过程
select ROUTINE_SCHEMA,ROUTINE_NAME,ROUTINE_TYPE
from information_schema.ROUTINES
where ROUTINE_TYPE=‘PROCEDURE‘ andROUTINE_SCHEMA not in (‘mysql‘,‘sys‘,‘information_schema‘,‘performance_schema‘);
#函数
select ROUTINE_SCHEMA,ROUTINE_NAME,ROUTINE_TYPE
from information_schema.ROUTINES
where ROUTINE_TYPE=‘FUNCTION‘ andROUTINE_SCHEMA not in (‘mysql‘,‘sys‘,‘information_schema‘,‘performance_schema‘);