Number of records in MySQL database

Well, that should be enough to get the count of all records in the current database:

SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_SCHEMA = DATABASE();

      

Surprisingly, I get different numbers every time I execute the above expression! At first I thought there was a problem with my database. But this is the same for the sample db provided by the MySQL developers.

Executing the above statement sakila

multiple times results in the following values:

46362
48104
45170
47060
48139

      

What am I doing wrong? This is mistake?

+3


source to share


1 answer


It's an InnoDB thing - you can read (id) in a table instead - but it's slow.



Because it is slow, InnoDB takes a random sample of lines, measures the sizes, then divides the total size to determine the approximate number of lines.

+6


source







All Articles