mysql获取表中数据行数

获取单个表的行数

使用count(*)或者count(1)

1 SELECT
2     count(1) AS count
3 FROM
4     table_name;

执行结果

获取两个表的行数

使用union组合每个select查询的结果集

例如,要在单个查询中获取customersorders表的行数

 1 SELECT 
 2     'customers' tablename, 
 3      COUNT(1) rows
 4 FROM
 5     customers 
 6 UNION 
 7 SELECT 
 8     'orders' tablename, 
 9      COUNT(1) rows
10 FROM
11     orders;

运行结果

获取数据库中所有表的行数

1 SELECT 
2     table_name, 
3     table_rows
4 FROM
5     information_schema.tables
6 WHERE
7     table_schema = 'dbname'
8 ORDER BY table_rows desc;

运行结果

原文地址:https://www.cnblogs.com/wangzhisdu/p/8297063.html