mySQL / MariaDB - count rows in a table

by
Jeremy Canfield |
Updated: April 08 2021
| mySQL / MariaDB articles
To count the number of rows in a table, first you need to log into your MariaDB or mySQL server or configure passwordless authentication and then use the -e command line option and the user must have the Select_priv.
Use the show databases command to view the databases you have already created.
show databases;
Something like this should be returned.
+--------------------+
| Database |
+--------------------+
| information_schema |
| db001 |
| mysql |
| performance_schema |
+--------------------+
Enter the database you wish to use. In this example, the database named db001 will be used.
use db001;
List the tables in the database.
show tables;
Something like this should be returned.
+------------------+
| Tables_in_db001 |
+------------------+
| table001 |
| table002 |
| table003 |
+------------------+
Count the number of rows in the table.
select count(*) from table001;
Something like this should be returned. Notice in this example that column001 type is varchar(200).
+----------+
| count(*) |
+----------+
| 16240145 |
+----------+
Did you find this article helpful?
If so, consider buying me a coffee over at