惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
V
Vulnerabilities – Threatpost
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
Y
Y Combinator Blog
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
MyScale Blog
MyScale Blog
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
量子位
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
L
LINUX DO - 最新话题
The Register - Security
The Register - Security
T
Tailwind CSS Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
T
Troy Hunt's Blog
Stack Overflow Blog
Stack Overflow Blog
Cloudbric
Cloudbric
S
Secure Thoughts
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
L
LangChain Blog
Recorded Future
Recorded Future
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
人人都是产品经理
人人都是产品经理
F
Full Disclosure
O
OpenAI News
Webroot Blog
Webroot Blog
A
Arctic Wolf
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
H
Heimdal Security Blog
B
Blog RSS Feed
Vercel News
Vercel News

博客园 - bwteacher

fastadmin中前端表格中字段状态动态加载问题 mysql操作错误 fastadmin操作 fastadmin下的多级联动 CentOS7安装Python3.10环境 表单提交fastadmin form jdk-24及tomcat-11.0.9(解压版)安装配置 mermaid基于 JavaScript 的图表绘制工具 HbuilderX 小随笔 v-bind和v-model的区别 v-if和v-show的区别 uniapp中@tap与@click点击事件的差异 PHP常用数学函数 距离-有这么多类 bootstrap.table汇总 selectpage汇总 jQuery没有匹配到任何内容,返回什么? js数组常用方法 thinkphp控制器名称命名相关 php常见错误码 ThinkPHP的join关联查询不使用默认的表前缀 阿里云虚拟主机创建https
mysql实用
bwteacher · 2026-04-27 · via 博客园 - bwteacher

一、获取l数据库中所有表的记录数

方法一:使用原生 SQL 查询 information_schema(推荐)

这是最高效的方法,因为它不需要先获取表名再循环查询,而是直接查询数据库的元数据。

注意:此方法获取的 TABLE_ROWS近似值(对于 InnoDB 引擎),但在数据量巨大时性能极高。

1. 获取每个表的记录数
phpuse think\Db;

// 假设你的数据库配置名为 'database',请根据实际情况修改
$dbName = '你的数据库名'; 
// 查询所有表的名称和行数
$list = Db::query("SELECT table_name, table_rows FROM information_schema.tables WHERE table_schema = '$dbName' AND table_type = 'BASE TABLE'");
dump($list);

2. 获取所有表的总记录数(求和)

如果你只需要一个总的数字,可以使用 SUM 函数:

use think\Db;

$dbName = '你的数据库名';

// 计算所有表行数之和
$result = Db::query("SELECT SUM(table_rows) as total_count FROM information_schema.tables WHERE table_schema = '$dbName' AND table_type = 'BASE TABLE'");

// 输出结果
echo "数据库总记录数约为:" . $result[0]['total_count'];