
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Finding total number of rows of tables across multiple databases in MySQL?
To fetch total number of table rows across databases, use aggregate function SUM() along with INFORMATION SCHEMA. Let us first create a table, which is in “web” database −
mysql> create table DemoTable1568 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1568 values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1568 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1568 values('David'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1568;
This will produce the following output −
+-------+ | Name | +-------+ | Chris | | Bob | | David | +-------+ 3 rows in set (0.00 sec)
Following is the query to create a table in the database “sample” −
mysql> use sample; Database changed mysql> create table DemoTable1568 -> ( -> Id int -> ); Query OK, 0 rows affected (0.99 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1568 values(101); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1568 values(102); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1568 values(103); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable1568 values(104); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1568;
This will produce the following output −
+------+ | Id | +------+ | 101 | | 102 | | 103 | | 104 | +------+ 4 rows in set (0.00 sec)
Here is the query to find total number of rows of tables across multiple databases −
mysql> select sum(table_rows) as TotalNumberOfRows from information_schema.tables -> where table_name='DemoTable1568';
This will produce the following output −
+-------------------+ | TotalNumberOfRows | +-------------------+ | 7 | +-------------------+ 1 row in set (0.19 sec)
- Related Articles
- Limit total number of results across tables in MySQL?
- Count(*) rows from multiple tables in MySQL?
- How can I sum columns across multiple tables in MySQL?
- MySQL query to count rows in multiple tables
- Finding the sum of integers from multiple MySQL rows in same column?
- Get total number of rows while using LIMIT in MySQL?
- List of non-empty tables in all your MySQL databases?
- Can we get total number of rows in a MySQL database?
- Getting Information About MySQL Databases and Tables
- Total number of fields in all tables in database?\n
- How can we get the total number of rows affected by MySQL query?
- MySQL count(*) from multiple tables?
- Inserting multiple rows in MySQL?
- How to lock multiple tables in MySQL?
- Insert records from multiple tables in MySQL

Advertisements