SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = '数据库名称';
mysql系统库:
mysql库:
mysql的核心数据库,主要负责存储数据库的用户、权限设置、关键字等mysql自己需要使用的控制和管理信息。
information_schema库:
information_schema是一个信息数据库,它保存着关于MySQL服务器所维护的所有其他数据库的信息。(如数据库名,数据库的表,表栏的数据类型与访问权 限等。
performance_schema库:
performance_schema主要用于收集数据库服务器性能参数。
sys库:
Sys库所有的数据源来自:performance_schema。目标是把performance_schema的把复杂度降低,让DBA能更好的阅读这个库里的内容。让DBA更快的了解DB的运行情况。
常用系统表:
information_schema是Mysql默认的一个数据库,用于记录数据库(SCHEMATA)、数据的表(TABLES)、表的列(COLUMNS)等信息
SELECT * from SCHEMATA;
SELECT * from TABLES
;
SELECT * from COLUMNS
;
常用系统查询命令:
#重新分析表
analyze table tb_name;
#查询前10条慢查询
select * from information_schema.slow_log l limit 10;
#查询某个数据库所有表记录总数(不精确)
SELECT TABLE_NAME,TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA = ‘pay’ ORDER BY table_rows DESC;
#若要准确的统计某张表的详细总记录数,建议用
count(*) from tb_name;
#统计服务器总的数据库记录
select count(*) from information_schema.SCHEMATA;
#根据表名定位数据库
select * from information_schema.TABLES
t where t.TABLE_NAME = ‘loan_lender’;
#查询某张表有多少字段
select count(*) from information_schema.COLUMNS where TABLE_SCHEMA=‘数据库名’ and table_name=‘表名’
#查询InnoDB当前事务版本号相关信息
select * from information_schema.INNODB_TRX limit 10;
mybatis 打印sql 日志:
mybatis-plus.configuration.log-impl = org.apache.ibatis.logging.stdout.StdOutImpl