FreeKB - mySQL / MariaDB count rows in a table
mySQL / MariaDB - count rows in a table

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 |
+----------+

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter b1d71 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |