MySQL – Count Number of Rows

To count total number of rows present in MySQL Table, select the database and run “SELECT COUNT(*) FROM tablename;” SQL query.

Open mysql command line interface and follow these steps.

1. Select the Database

You can select the database using USE database;.

MySQL - Get number of rows present in MySQL Table

2. Query to Count number of rows present in MySQL Table

We shall count the total number of rows in students table of school database.

MySQL - Number of rows in Table

There are two rows in the table. Without printing all the row data, we can get just the number of rows in the table using COUNT keyword.

Run the following query to get the total count of rows present in a table.

</>
Copy
SELECT COUNT(*) FROM table_name;

The result is COUNT column with number as single row.

MySQL - Count total number of rows in table

Output of the query is just what we need: number of rows present in table.

Conclusion

In this MySQL Tutorial, we have learnt to count total number of rows present in MySQL Table.