To get the total number of rows in a MySQL database, you can use aggregate function SUM() along with inbuilt column TABLE_ROWS from INFORMATION_SCHEMA.TABLES.
The syntax is as follows−
SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = database();
登录后复制
假设我们正在使用名为'sample'的数据库。
现在我们将获取MySQL数据库中的总行数−
mysql> SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = database();
登录后复制
这将产生以下输出−
+-----------------+
| SUM(TABLE_ROWS) |
+-----------------+
| 2043 |
+-----------------+
1 row in set (22.11 sec)
登录后复制
以上就是我们可以获得 MySQL 数据库的总行数吗?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!